Skip to content

Tag: sql-server-2008

Fetching Database Name with Space

Thanks for looking into my post. I am trying to run a query across all the database in SQL Server but the cursor is not fetching if the database contains space and the database is online. Code Error Answer Delimit Identify your object’s name. In normal terms that would be wrapping it with brackets ([]),…

Get Row value as Column Header

I have two tables as below. I want to join these two tables and need to set the column values of second table as column header as shown below. How can I achieve this? Table1  table2 The output table should be Answer You can use Dynamic Pivot as below-

setting time range in SQL Developer

I am working on a dataset that contains car accidents and their time of occurrence. (the data set exists in SQL Server under the name accident). I have a column that is in date format. I would like to extract the time from the column. Then add a new column called lightining_period label the time as daytime or…

Repeat insert statement without GO

Is there a “nicer” way to achieve the same results as this SQL query: Which is to insert 300 default all NULL (except PK Id col) new lines into an empty table? It seems to take a while! Also, the value 300 could be completely variable e.g. something like but that obviously doesn’t work: Answ…