Not quite sure what these are to be honest. I am looking at someone else's SQL query and they have SELECT statements which look like this:
SELECT
Something,
Something
FROM
MyTable(DEFAULT, DEFAULT, DEFAULT)
And Another which looks like this:
SELECT
Something,
Something
FROM
MyTable(NULL)
Christ, when I do a SELECT statement, I only put the table name there and that's it.
Could someone please tell me what the (DEFAULT, DEFAULT, DEFAULT) would be used for? and also the (NULL) - I'm sure there are many more of these once I know what they are.
My apologies if this is a duplicate question, but I couldn't seem to find an answer anywhere.
Thanks!
Mike
It appears that MyTable(DEFAULT, DEFAULT, DEFAULT) is a table-valued function call. This function has three parameters, and all these parameters should take default values.
In Management Studio, Look under Programmability->Functions->Table-valued Functions. There you will see the definition of the function.
Related
I have created a table that has a column with the name started of type datetime. I was very surprised to see this turn blue when I copied my select statement into management studio. When looking at the list of reserved words for SQL in the Microsoft documentation (see here), I cannot find the word started.
What is it? What does it do?
A very old SSMS problem.
I'm afraid M$ doesn't care about some tokens treated as keywords.
See this.
I don't think so. There is no keyword exist with the name started.
I was able to create table
SQLFiddle Demo
I use SQL Server 2008 with Borland Delphi in order to develop my applications. Since recently I'm getting a very weird error. I have created several scalar functions that I use in my application, but I'm having a problem with a customer, in his company my software returns the following error when I call my scalar functions:
Cannot find either column “dbo” or the user-defined function or aggregate “dbo.FunctionName”, or the name is ambiguous."
I've already searched a lot, even here, so keep in mind that:
The function exists;
I'm quering the correct database;
There's no typos;
Owner schema is dbo;
This problem occurs with ALL MY FUNCTIONS;
And the weirdest...
It only happens when I call them from my application, if i run the EXACTLY SAME code at the Query Analyzer using the same user, it will run just fine.
I have this same functions in several other customers, and they don't have any problem. Could it be a SQL Server problem?
Ps: Sorry for my poor English, first question here.
I don't know how QueryAnalyzer calls your functions, but I know this error.
Usually, when you have user-defined functions, you need to prefix the function with the schema name.
So if your function is in schema "dbo", and the name is "fnPadLeft", you need to call the function in code like this:
SELECT
id
,some_field
,dbo.fnPadLeft(some_other_field)
FROM YOUR_TABLE_NAME
If you call it like this:
SELECT
id
,some_field
,fnPadLeft(some_other_field) -- lacks dbo.
FROM YOUR_TABLE_NAME
Then you'll get "no such function".
This only happens to scalar functions btw. (you specifically mentioned this), table-valued functions (and all other non-function things) are not affected by this "feature".
It might also be that you have the same functionname in two schemas (also take a look at the functions in the master database). Maybe your "other functions" are table valued functions.
In SSMS and its immediate or locals window, is there a way to see the contents of table variable?
I can select and view the value of scalars, but I can't seem to find a way to query the contents of tables or even run
SELECT * FROM #someTableVarInMySproc
in the immediate window. Is there any way to do this?
No, sorry, this is not possible in current versions of Management Studio. It has been asked for, and it's been stated that they are considering something similar in a future version. You can vote and add constructive comments on the following items, though there is no guarantee they'll ever actually do it:
http://connect.microsoft.com/SQL/feedback/details/623353
http://connect.microsoft.com/SQL/feedback/details/582167
http://connect.microsoft.com/SQL/feedback/details/454870
http://connect.microsoft.com/SQL/feedback/details/363054
The first item in that list has an interesting workaround:
In addition to the obvious caveat that you may not be able to inject additional code to capture the data in an XML variable (because after all, if you can do this, you could also add old-school debugging techniques like SELECT * FROM #table), and the cumbersome nature of trying to read this information from XML, Management Studio 2012 crashed on me the first time I tried to do this - so if you're going to try it, make sure you do so in an isolated instance.
I have a simple Ms-Access database with one table named Student and it has two columns ID and Name.
When I the database in Access and enter the query
select * from Student where Name like 'J%'
in its SQL view, it gives an empty resultset.
But the table has a Name called John.
I tried with other databases and tables also with like-queries, but none works.
Can anyone please tell if there is any special reason for this???
Thank you
Edit:
The same query works with c sharp code
What you need is
select * from Student where Name like 'J*'
or possibly (because I don't have access handy to check, possibly either will work)
select * from Student where Name like "J*"
The * is the wild card character for MsAccess
From my experience in the past... yes access syntax has some minor difference that make even simple things a trouble.
I don't remember how but check around a way to make access show the sql from some results you retrieved in a graphical way, there must be some show sql button somewhere.
Once there examine carefully the sql syntax, then test your sql in access' editor.
So the main idea is let access show you the way!
I must have some permissions wrong, but I can't figure out how. The following code is simplified but I can't even get this to work
CREATE FUNCTION ufTest
(
#myParm int
)
RETURNS int
AS
BEGIN
DECLARE #Result int
SELECT #Result = #myParm + 1
RETURN #Result
END
GO
Then I just want to be able to call the function from a stored procedure:
CREATE PROCEDURE dbo.[uspGetGroupProfileService]
#id int
AS
BEGIN
SET NOCOUNT ON;
DECLARE #otherId int;
SET #otherId = dbo.ufTest(#id);
END
SQLServer keeps telling me that it can't find dbo.ufTest. It shows up under [DB]\Programmability\Functions\Scalar-valued Functions but I can't figure out how to use it.
Anybody have any idea what I'm doing wrong?
EDIT
As indicated by the selected answer below, you can't always trust the SSMS Intellisense. One thing that you can try, other than just trying to execute the script, is forcing an Intellisense refresh with CTRL + SHIFT + R
https://blog.sqlauthority.com/2013/07/04/sql-server-how-to-refresh-ssms-intellisense-cache-to-update-schema-changes/
Works for me.
Try CREATE FUNCTION dbo.ufTest ...
I assume your default schema can't be dbo and it's ending up in a different schema. Otherwise the only explanation I can think of is you might need to grant permissions on it.
Script out the UDF and check the schema name. It's probably not dbo. I would change the UDF definition to specifically include dbo. In other words:
CREATE FUNCTION dbo.ufTest
Had the exact same problem and mine got fixed by simply restarting SQL Server Management Studio.
Just posting this in case anyone else did everything right and is still not able to call his function.
I just had an issue where this was the error and all of the advice on this column was failing as well.
Be sure double check your function declaration type and usage of that type.
I declared a return-type table and tried to call it with Select functionName() where I needed to use SELECT * FROM functionName()
As a last resort if any of the above and especially #jrdev22's answer did not help you (and left you stumped why), restart the SQL Server service in Configuration Manager since restarting the SSMS alone sometimes does not reset everything (e.g. similar to when creating a new login instance but not being able to login with it).
SQL Server Configuration Manager> SQL Server Services > SQL Server > Restart
Try calling it with a select instead of a set. And you checked that out belongs to the dbo schema?
It appears it might be a bug in the query editor. The Function appears in the tree in the right place but even naming the function dbo.xxxxxx the function doesn't appear in the query editor until you close and open a new session, then it appears if you type in dbo.
If you change the name of the function the old non existing fuction is avalable but not the new name. Refresh doesn't fix this only closing the session and starting a new one.
Why I say this might be a bug is that the permissions properties for Table function includeds a blue link to the schema properties but the Scalar functions it doesn't. So it may be a deeper lying bug in the way the schema is set up in the first place for which there may be a work around. Or maybe the schema in the database I am working on has not been set up correctly.
Hopefully someone else can shine some light on this issue.
If you are unable to find the function that you have just created there are two reasons for it.
you are using the wrong function name you need to add dbo.function name to get it.
I've also found one more issue like even though correct name is entered and also it is existing in the object explorer after refreshing you are unable to find it when you are trying to use the function.
In this case simply close the sql server and reopen it and you should be able to see the function.