To get the current date in Sql Server queries and stored procedures, you use the GetDate() method. But what about to add a day or two to the current date, or add a month or years? To do it, you use the following query:
Add One Day
SELECT DateAdd(dd, 1, GetDate())
Add One Month Continue reading
There are 2 ways to Convert a string to a UniqueIdentifier (GUID) in SQL Server:
SELECT CAST(‘449141d9-86c9-449d-be2c-1f171b4f4567’ as UNIQUEIDENTIFIER)
SELECT CONVERT(UNIQUEIDENTIFIER, ‘449141d9-86c9-449d-be2c-1f171b4f4567’)
I needed to remove all the special characters from a field in a particular table in SQL Server to be used for searching purposes. After searching (binging :P)… I found the next SQL Server Function which did the trick.
This Function Removes any special character from the string value passed. All characters except 0-9, a-z and A-Z are all removed, whilst the remaining characters are returned back.
ALTER FUNCTION dbo.RemoveSpecialCharacters
RETURNS VARCHAR(256) WITH SCHEMABINDING
IF (@s is null)
RETURN null Continue reading
The following error kept popping up when trying to import data from a flat file source of type CSV to be imported in a table in SQL Server:
The product level is insufficient for component source “filename.csv”
To solve this problem, you need to install the Service Pack 2 of SQL Server 2005 from this link.
If you find other solutions… please let me know 😉
Next is the code to copy database diagrams from one database to another (tested on SQL Server 2005 and 2008)
DROP TABLE dbo.#tempsysdiagrams
–this will copy your database diagrams into a temporary table
select * into dbo.#tempsysdiagrams from sysdiagrams Continue reading