Feeds:
Posts
Comments

Posts Tagged ‘SQL’

SQL – Get first day of the year

I m found a way to get the first day of the year without hardcode in the stored procedure.
here the SQL script.
convert
(char(20), convert(char(4), year(getdate())) + ‘/01/01′, 111)

To test it, simply put “select” in front of the pink color script above. 
The result, if your system current year is 2008, it will return 2008/1/1!

Read Full Post »

SQL – Sum a Union

to get a total value from both query, the only way to do is UNION both query and a Select Statement on top of UNION.
SELECT Sum(Col1) as A, Sum(Col2) as B
FROM ( SELECT Col1, Col2 FROM TableA
UNION Select Col1, Col2 From TableB ) A

Read Full Post »

substring for MSSQL

I have a column called FileName with values such as “100.wmv, 200.wmv, 999.wmv”, but i just want to display “100, 200, and 999″ without wmv extension.
so I just use substring to solve the problem
select substring(FileName, 1, 3) as FileName from [TableA]
Here the explaination to use : SUBSTRING(string to manipulate, start index, length of string to [...]

Read Full Post »