Category Archives: SQL Server 2008

Optimize your SQL Query using temporary table

If you are using JOIN which considerably slows your query or report, you may create a temporary table inside your stored procedure. Use this temporary table which contains filter data to use in the report. This will make the query … Continue reading

Posted in SQL Server 2008 | Leave a comment

Row_Number SQL Server

Row_Number or Sequence Generator in SQL Server Is is used to generate a sequence number or a row number in a result table. That is if you want to run a query and you rank certain records in certain order, … Continue reading

Posted in SQL Server 2008 | Leave a comment

Quick SQL Scripts

Find start date of the year in SQL SELECT Cast(Datepart(yy,Getdate()) AS VARCHAR(4)) + '-1-1' year  

Posted in SQL Server 2008 | Leave a comment

compare two null values in sql

If you compare two values and either of them can be null or one of them null equal (=) operator does not work. Equal operator is not null sensitive. To compare the two you have to changed null to valid … Continue reading

Posted in SQL Server 2008 | Leave a comment

SQL Server 2005 Instances do not show up in Server 2008 R2

I updated my SQL Server 2005 to SQL Server 2008. Everything worked great. After a few weaks later, I tried to connect to the db in SQL Server Management Studio after I had restarted the PC and it won’t connect. … Continue reading

Posted in SQL Server 2008 | Leave a comment

JOIN using LIKE in SQL

Q. Can I join tow tables using like (more flexible criteria) than exact match? Ans. Yes [sql] — create test table first create table #A ( id varchar(10) ) create table #b( number varchar(5) ) insert into #A values(‘123’) insert … Continue reading

Posted in SQL Server 2008 | Leave a comment

BETWEEN DATES SQL Server 2008

When dealing with dates, remember there is not such field as date in SQL Server 2005/2008. There is datetime field. For reference there is a date type in MySQL which I think is very useful. There could be problems when … Continue reading

Posted in SQL Server 2008 | 1 Comment

The column ‘LOCK_ID’ was specified multiple times for ‘BB’.

SQL Server 2008 Error Message: The column ‘LOCK_ID’ was specified multiple times for ‘BB’. Example: select BB.LDC_ACCT_ID from ( select * from STUDENTS S JOIN RECORDS R on S.STUDENT_ID = R.STUDENT_ID ) as TEMP If you run this query in … Continue reading

Posted in SQL Server 2008 | Leave a comment

Error Locating Server Instance Specified

Connecting to the server through a third party software/interface can give you the following error. [SQL Native Client]SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [SQL Native Client]Login timeout expired [SQL Native Client]An error has occurred while establishing a connection … Continue reading

Posted in SQL Server 2008, Uncategorized | Leave a comment

SQL Select * into from

If you want to copy or backup your table in the database, use the following SQL command. select * into newtable from oldtable The new table is created on the fly. You do not need to create it. A more … Continue reading

Posted in SQL Server 2008 | Leave a comment