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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 IF in T-SQL Column Expression

Author  Topic 

grrr223
Starting Member

30 Posts

Posted - 2004-02-23 : 20:54:09
PLEASE PLEASE PLEASE HELP ME!!! Sorry, but this has been driving me crazy all day and I'm about to kill someone or something.

I have a report in an Access Data Project that I want to group in two groups:

1. Previous Activity - Records with doc_date < @StartDate
2. Current Activity - Records with doc_date >= @StartDate

Since Access's grouping features are faily me, I have decided to simply add a column to to the query I am using as the recordsource for my report that simply evaluates to 0 if the record meets condition 1. and evaluates to 1 if it meets condition 2. I will then group my report on that column to get exactly the two groups I want.

I have posted this here instead of in the Access forum because Access Data Projects use T-SQL, and I am looking for T-SQL syntax to get my column into my query. I already know how to group by the column.

I essentially want the equivalent of IFF(doc_date < @StartDate,0,1) but T-SQL obviously doesn't handle JET/VB operators, so if someone could PLEASE help me with this simple question by telling me what the SELECT statement might look like to add this column to my query, I'll be your best friend!

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-02-23 : 21:41:56
As in the example I gave you in the other post,

CASE WHEN docdate < @StartDate THEN 0 ELSE 1 END

is the T-SQL equivalent of

IIF(docdate < @StartDate,0,1)

in VB/JET.

Read Books on-line for more about T-SQL, or a good T-SQL book.

- Jeff
Go to Top of Page

grrr223
Starting Member

30 Posts

Posted - 2004-02-24 : 11:37:41
THANK YOU!

Of course, it's such a simple thing I just could never get the syntax right and I was pulling my hair out.

Access Data Projects are awesome, and you're right, at this point I really just need a good T-SQL book. And to move any further along in my Access development, I need a good VBA book. This project is certainly a learning experience. :)
Go to Top of Page
   

- Advertisement -