Handy little nugget to check if a string exists within another string. Particularly useful if you’re working with a delimited string as I was, as it makes dealing with the delimiters irrelevant.
SELECT * FROM table
WHERE CHARINDEX('string1', 'string2') != 0
In this instance ‘string1’ is the string you’re searching for in ‘string2’. Obviously these could be substituted for columns in a table or whatever.
As I seem to keep forgetting this most simple of SQL statements…
SELECT * INTO NewTable FROM existingdb.dbo.existingtable;
When handling SQL Exceptions, it’s pretty handy to know which error codes relate to which errors…or at least it is for me as I’m currently writing some exception handling routines that work off the error code. So to get a list of all SQL error codes, along with descriptions, simply perform the following SELECT statement on the master database:
SELECT * FROM sysmessages