SQL server procedures indentation changes after I re-check using sp_helptext - ssms

In my SQL Server 2014 Management Studio I am facing indentation issue. Like if I create a stored-procedure with proper indentation like tabs, spaces etc.. and if I again check the sp then I see no indentation which I gave while creating the procedures.
Created with proper spacing etc...
What I get after rechecking-

When you execute sp_helptext in SSMS:
exec sp_helptext 'YourSpName'
try setting output type to "Results to Text" instead of "Results to Grid".
You can use the shortcut CTRL+T for this or you can enable it from menu Query/Results To/Results To Grid.
This should preserve indentation.

Related

Custom delimiter in SQL Server set in "Results to Text" options doesn't work

I am interested in saving the result of a SQL query, like a SELECT statement, as a pipe (|) delimited text file in SSMS.
I can do that using the Export wizard.
However, it seems there's a simpler method by setting a "Custom delimiter" in Tools>Options under Query Results>SQL Server>Results to Text as shown here:
Then, if I specify "Results to Text" or "Results to File", I am supposed to get the pipe delimited result.
This is also outlined here:Obtaining Pipe Delimited Results from SQL Server using SSMS
But, doing this I still get the usual output with either Results to Text or File.
I don't know what I'm missing or doing wrong.
Thanks for your help.
Thanks to #AlexYu, the answer is simply applying the "turning it off and on" trick. Closing and re-opening SSMS is required before the change in this setting takes effect.
Incidentally, disconnecting and re-connecting to the SQL server doesn't work in this case. I have done some rudimentary tests and it seems this also applies to other options here, for example under Query Results>SQL Server>Results to Grid.
I was using Microsoft SQL Server Management Studio v17.9.1, build number 14.0.17289.0.
I think "Query Results" is able to delimit the results by a custom character, only if all the datatype is varchar. I did what you wrote in the description and additionally I casted all the columns to varchar.
SELECT TOP (1000) CAST([COL_A] as varchar) as 'COL_A'
,CAST([COL_B] as varchar) as 'COL_B'
,CAST([COL_C] as varchar) as 'COL_C'
FROM TABLE_NAME;

DBeaver SQL Server GO invalid

Is there a way to get DBeaver to use SQL Server's alternate "GO" delimiter? Squirrel SQL allows this via a SQL Server preference (statement separator).
This should work.
Open connection editor
click on "Edit Driver".
Switch tab on "Adv.
parameters".
Set "Script delimiter" value to "go".
GO batch support
#Jonathan's screen seems to not exist anymore with actual version. This works for me :
Right click on your connection and select "Edit Connection".
Under SQL Editor -> SQL Processing, click the checkbox for "Datasource settings" and then change the "Statements delimiter" to "GO".
There is a setting in the DBeaver preferences that allows you to specify a delimiter, but it seems to be not working. Whatever gets entered and saved in the preferences is ignored.
Screen capture of relevant DBeaver preferences pane
In the meantime, you can always replace all instances of 'GO' in your SQL with a semicolon ';'.

Is there a way to bind SSMS 2012 keyboard shortcuts to a procedure in a way where I can pass the fully qualified object name?

In SSMS 2012, is there any way I can bind a keyboard shortcut (e.g. Ctrl-5) so that I can highlight a qualified object name (e.g. master.sys.objects) and invoke my own procedure using that object name as the argument?
I know that this does work if I explicitly add quotes or brackets around the object name prior to using the keyboard shortcut (e.g. highlight the string 'sys.objects', but this becomes tedious when wanting to use my shortcut easily by directly highlighting tables in existing queries.
For more context, I noticed that Alt-F1 (the shortcut for sp_help) now supports fully-qualified object names. For example, highlighting sys.objects and pressing Alt-F1 works perfectly in SSMS 2012 (it does not in SSMS 2008). Here is the relevant Connect issue that describes this enhancement.
However, when looking at the keyboard binding for this shortcut, it looks like this action should be synonymous with invoking sp_help on the highlighted text:
This turns out not to be the case, as you can see by running the following two calls to sp_help, both of which fail with error Incorrect syntax near '.'.:
USE master
GO
EXEC sp_help sys.objects
GO
EXEC sp_help master.sys.objects
GO
If there is a way for me to be able to invoke my own procedures similar to the way sp_help can be invoked on qualified objects without brackets or quotes, I would love to know!
SSMS 2012 supports 2 part names without quotes, for 3 part names you still need the quotes.
I still have not found any plugin that supports what you want, perhaps you could make a macro on SSMS Boost(http://www.ssmsboost.com/) to automatically add brackets, run your command then remove the brackets. I have not tried to do anything like this with it but it should be possible

SQL Server Report Parameter

I'm create a SQL Server Report using Business Intelligence tool (visual studio shell 2005) for SQL Server 2008.
I'm calling a stored procedure with 2 parameters. I've tried - Report-> Report Parameter, Added two parameters name them Days and Count.
In the Data panel "command type:text"
exec dbo.DataReport #Days, #Count
error: Must delcare the scalar variable "#Days"
Does anyone know how do get this too work.
Try changing the command type to Stored Procedure, i'm sure its worked for me in the past
If changing the command type to Stored Procedure like was suggested didn't work, try opening the Dataset dialog box and going to "Parameters" tab. Make sure that both parameters ("#Days" and "#Count") are in the list and that each one has a value.

Debugging a SQL Query

Does SQL Server 2008 have a built in debugger? I've got a stored procedure that returns an error if it is fed a string of alphabetic characters (as opposed to numeric) and I'd like to be able to determine what line it gets to before returning an error.
Yes, you can debug SQL stored procedures, functions, triggers, etc.
http://www.mssqltips.com/tip.asp?tip=1695
SQL Server Management Studio can debug stored procedures in SQL Server 2008. Open your stored procedure, and instead of hitting the "execute" button (the red exclamation mark) hit the "debug" button (the green "play" arrow).
http://www.mssqltips.com/tip.asp?tip=1695
I would add PRINT 'Checkpoint A passed' type statements at various points to see how far it gets.. the output would appear on the Messages tab. It's a lame way of debugging, but it works.
insert into blah blah blah
print 'Passed the insert'
select blah
print 'Passed the select'
You can try the Transact SQL Debugger
I've never used it but remember reading about it somewhere.