WAITFOR

Use to block execution. While executing a WAITFOR statement the transaction is running and no other requests can run under the same transaction. Bear in mind that if the server is busy the thread may not be immediately scheduled. —-Delay for 20 seconds WAITFOR DELAY ‘000:00:20′ SELECT ’20 Second Delay’ GO —-Delay till 7 AM […]

Read More

Specifying Values In Statements

Numeric Values Simply use the value as is: “WHERE SomeFieldName=4” Text Values Surround the value in single qutoes: “WHERE SomeFieldName=\’This Is The Value\'” When you need to include single quotes in the string (e.g. ‘St Mary’s’) use a doudle single quote. E.g. in VC++: NewString = NewString->Replace(“\'”, “\’\'”); //Replace all ‘ with ” (needed if […]

Read More

DateTime

Equivalent to MySQL Now() Use GETDATE(): UPDATE table SET date = GETDATE(); This returns the current database system timestamp as a datetime value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of SQL Server is running. Using Fields Stored Using GETDATE() In […]

Read More

Does Table Exist

SqlCommand1 = gcnew SqlClient::SqlCommand(); SqlCommand1->Connection = SqlConnection1; SqlCommand1->CommandType = CommandType::Text; SqlCommand1->CommandText = “SELECT count(*) FROM sysobjects WHERE name =’tblLocations'”; if (!Convert::ToBoolean(SqlCommand1->ExecuteScalar())) //True if label does exist { }

Read More