Create custom configuration functions in SQL SERVER [duplicate] - sql

This question already has answers here:
Create a global static variable in SQL Server?
(4 answers)
Closed 9 years ago.
I want a function similar to ##servername to be created. So, the new ##mycustomname will return something I set up and then I can use ##mycustomname in my deployed T-SQL Scripts.
Is there a way to do it?

No you can't. These are reserved keywords.
What you want to be somewhat equivalent to global variables, which unfortunately does not exists.
The best you can do is declare a function.

Related

Get name of current procedure in VBA? [duplicate]

This question already has answers here:
Get Name of Current VBA Function
(12 answers)
Closed 7 years ago.
For Error handling, I would like to have the current procedure name pushed into a call stack.
Is there any simple way to accomplish this outside of having to hard-code the name as a local variable for each subroutine?
Unfortunately, no. VBA code has no access to the call stack. A decent technique is here under Advanced Error Handling: https://www.fmsinc.com/tpapers/vbacode/Debug.asp

How to Check the given string is a reserved keyword in sql server [duplicate]

This question already has answers here:
Check if string is SQL Server Reserved Keywords or not
(3 answers)
Closed 8 years ago.
How to check whether the given string is a reserved keyword in sql server.
I checked a lot in google ,but i didn't find one!!
for eg: If i am giving the input String as 'Order',sql statement should
return whether it is reserved keyword.
Is there any built-in stored procedures or function to do this? Any help would be appreciated.
There is no built-in function to do that.
Here is the list of the known identifiers.
http://technet.microsoft.com/en-us/library/ms189822.aspx
I suggest to put these in an table and use it in a function / stored procedure.

sql server select from case db [duplicate]

This question already has answers here:
How to use a variable for the database name in T-SQL?
(4 answers)
Closed 8 years ago.
I have 2 db on one server.
I need to write procedure that does select basing on #db variable.
I know 2 possibilities for this:
I declare #SQL nvarchar(max) and generating my query in plain text. Then i do exec #SQL.
Bad variant imho.
I do 2 similar queries and use if #db='' 1st query else 2nd query. Another bad variant because it is code duplicate.
Question is - is there any way to do like this or similar: select * from #db.dbo.table?
Using "exec #SQL" isn't evil. If it gets the job done and you're not exposing yourself to any security risks then it may be the best way to go. Another option would be to consider using a real programming language like c# (or whatever your preference is) since they are better equipped to handle these sort of dynamic requirements.

Should we end the statement in T-SQL with semi-colon? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
When should I use semicolons in SQL Server?
When we are writing a SQL script in T-SQL, should we end each statement with a semi-colon? Does semi-colon work like 'GO' keyword? As of now, I see that it doesn't really matter, but I would like to know which is the best practice?
It's good to get into the habit now because CTE/WITH and MERGE need it, as well as some Service broker stuff as mentioned in the other question. Of course, you could use ;WITH cTE AS ...
C# etc monkeys have been doing it for years.
It won't work with GO because it isn't a keyword. It's a directive for SSMS and other tools to break a larger script into batches.

IS vs AS keywords for PL/SQL Oracle Function or Procedure Creation [duplicate]

This question already has answers here:
What is the difference between "AS" and "IS" in an Oracle stored procedure?
(6 answers)
Closed 9 years ago.
I have been trying to find out what the difference is between the IS and AS keywords in PL/SQL when creating an Oracle function or procedure.
I have searched and have been unable to find any information on this. Does anyone know the difference?
I've never known there to be a difference. The Oracle documentation implies that they are synonyms:
The function body begins with the keyword IS (or AS) and ends with the keyword END followed by an optional function name.
Same as DISTINCT and UNIQUE in select statements.
i.e, there is no material difference between 'IS' and 'AS'.
Backwards compatibility and meeting standards