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
 calculate field

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2010-11-17 : 10:44:01
Hi All.
I would like to calculate field Result. What wrong in my select?

SELECT DateT
, Sum(case when Result = 'NEG' then 1 else 0 end
FROM Table1

Thanks.

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-17 : 10:58:11
Missing ) after end.
Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2010-11-17 : 11:08:03
Thanks for replay.

That is just wrong type in the post. When I run select I got error message: "Incorrect syntax near 'NEG'."

Thanks.
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-17 : 11:12:11
Can you give the table structure and sample data?
Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2010-11-17 : 11:32:51
TABLE [dbo].[Table1](
[Test_id] [bigint] IDENTITY(1,1) NOT NULL,
[DateT] [datetime] NULL,
[Result] [varchar](50) NULL
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[Test_id] ASC

Data:
Test_id DateT Result
11 5/20/2003 0:00 NEG
12 5/30/2003 0:00 ASS
13 5/21/2003 0:00 NEG
15 6/4/2003 0:00 NEG
16 5/1/2003 0:00 HGL
17 6/19/2003 0:00 NEG
18 5/20/2003 0:00 NEG
19 6/3/2003 0:00 NEG
20 5/30/2003 0:00 ASS
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-17 : 11:53:14
What should the expected outcome be?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-11-17 : 12:42:50
this



SELECT DateT, Sum(case when Result = 'NEG' then 1 else 0 end) AS Col
FROM Table1
GROUP BY DateT




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2010-11-17 : 15:42:44
Thanks for help. I forgot GROUP BY DateT
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-11-17 : 16:21:53
np op

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -