Pasting from SQL Server Management Studio to Excel concatenates columns

This is an issue with Excel. After you paste the results into Excel, go to the “data” option and choose “Text to Columns”. Then click on “delimited” and be sure that “tab” is checked on the next window. This will convert the data into columns. And, Excel remembers the settings, so it will paste correctly … Read more

How to select last one week data from today’s date

Yes, the syntax is accurate and it should be fine. Here is the SQL Fiddle Demo I created for your particular case create table sample2 ( id int primary key, created_date date, data varchar(10) ) insert into sample2 values (1,’2012-01-01′,’testing’); And here is how to select the data SELECT Created_Date FROM sample2 WHERE Created_Date >= … Read more

Optional parameters in SQL Server stored procedure

You can declare it like this: CREATE PROCEDURE MyProcName @Parameter1 INT = 1, @Parameter2 VARCHAR (100) = ‘StringValue’, @Parameter3 VARCHAR (100) = NULL AS /* Check for the NULL / default value (indicating nothing was passed) */ if (@Parameter3 IS NULL) BEGIN /* Whatever code you desire for a missing parameter */ INSERT INTO …….. … Read more