Wednesday, February 23, 2011

Show Total in SQL

SELECT distinct(b.fieldname),CONVERT(varchar,SUM(a.fieldname),1) as total
 from tablename a, tablename b
 where  a.fieldname=b.fieldname
 group by b.tablename

Wednesday, February 16, 2011

Insert Record from Temp Table to Actual Table

insert into ActualTableName
Select FiledName from TempTable$
where FieldName NOT IN(select FieldName from ActualTableName)

Monday, February 7, 2011

Previous Month Count in SP

CREATE PROCEDURE [dbo].[SP_NAME]

AS
BEGIN

select FieldName,count(FieldName)as alias from tablename
where fielddate>= DATEADD(month, DATEDIFF(month, 0, getdate()) - 1, 0)
AND dt < DATEADD(month, DATEDIFF(month, 0, getdate()), 0)
group by FieldName
 HAVING COUNT(FieldName) >= 1
 ORDER BY FieldName ASC
END