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
 Other Forums
 MS Access
 Parameter value is equivilant to field name

Author  Topic 

JAdauto
Posting Yak Master

160 Posts

Posted - 2004-05-03 : 22:06:49
I need to pass a parameter value for the month the user wants to report on. These parameters are all numeric. So, it would be 1 for January, 2 for February, etc. But the fields in our table are named 'January', 'February', etc and are bit fields. (Fields for all 12 months and true if they are to be charged that month)

I wrote something like this:

Select *,
CASE @MonthNumber
WHEN 1 THEN 'January'
WHEN 2 THEN 'February'
WHEN 3 THEN 'March'
WHEN 4 then 'April'
End as MonthName
FROM Charges
WHERE MonthName = 1

This is certainly not working because Monthname is not a column name. I was just wondering if there was a way to accomplish this with our numeric parameter.

Thanks again,
JAdauto

nr
SQLTeam MVY

12543 Posts

Posted - 2004-05-03 : 22:27:54
select * from tbl where @MonthNumber = 1 and January = 1
union
select * from tbl where @MonthNumber = 2 and February = 1
union
...

then join to that.

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

cinrain
Starting Member

1 Post

Posted - 2004-05-04 : 12:07:04
strange table structure. why set 12 fields for month flag,there must be a special request...
Go to Top of Page
   

- Advertisement -