Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need SQL Query

Author  Topic 

bhanu
Starting Member

1 Post

Posted - 2012-06-18 : 06:11:49
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/c2fbd89c-d954-43b1-946b-f66b63efee45

CH.Bhanu

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-18 : 07:05:36
Your field value dodesn't seem to be a single datatype. Sometimes a number, sometimes a date, sometimes a time.
Not something you should try summing.
Think yoou need to simplify the data structure first.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-18 : 12:16:05
should be doing something like this i guess

SELECT EntityItemId,SUM(IntVal) AS Total
FROM
(
SELECT EntityItemId,
CAST(MAX(CASE WHEN FieldID = 19 THEN FieldValue ELSE NULL END) AS datetime) AS DtVal,
CAST(MAX(CASE WHEN FieldID = 21 THEN FieldValue ELSE NULL END) AS int) AS IntVal,
...
FROM table
GROUP BY EntityItemId
)t
WHERE DtVal > = '20111220' AND DtVal < '20111221'
GROUP BY EntityItemId


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -