December 31, 2011 at 12:05 am
Hello
My Table Structure is
Id Sunday Monday Tuesday Wednesday Thursday Friday
now i want to write select query which should return the records under the column. I want to check the caption of column and caption matched the it should return the records.
Is it possible and how?
December 31, 2011 at 12:07 am
Please explain it little bit more.
Shatrughna
December 31, 2011 at 12:25 am
In this table I am storing Quantity daywise.
as
Id Sunday Monday Tuesday Wednesday
1 2.00 2.00 2.00 2.00
now i want to get back the quantity of the day sunday.
December 31, 2011 at 12:29 am
Your table is badly designed. Day column should appear in rows it would make your query a lot easier.
SELECT COL_NAME
FROM YOUR_TABLE
WHERE DAY=’SUNDAY’
If you can’t change the table design, you should go with dynamic query. It would be painful exercise.
For More: http://msdn.microsoft.com/en-us/library/ms188001.aspx
December 31, 2011 at 2:06 am
I got Solution
Select
Case when datename (dw, getdate())='Monday' then Monday else
case when datename (dw, getdate())='Tuesday' then Tuesday else
case when datename (dw, getdate())='Wednesday' then Wednesday else
case when datename (dw, getdate())='Thursday' then Thursday else
case when datename (dw, getdate())='Friday' then Friday else
case when datename (dw, getdate())='Saturday' then Saturday else
Sunday end end end end end end[Qty]
from dbo.tblHawkerComplimentarySubs
where HawkerID='15001' and ItemId='1'
December 31, 2011 at 2:35 am
amitsingh308 (12/31/2011)
I got SolutionSelect
Case when datename (dw, getdate())='Monday' then Monday else
case when datename (dw, getdate())='Tuesday' then Tuesday else
case when datename (dw, getdate())='Wednesday' then Wednesday else
case when datename (dw, getdate())='Thursday' then Thursday else
case when datename (dw, getdate())='Friday' then Friday else
case when datename (dw, getdate())='Saturday' then Saturday else
Sunday end end end end end end[Qty]
from dbo.tblHawkerComplimentarySubs
where HawkerID='15001' and ItemId='1'
Surely you got it but to produce the final results your query needs to evaluate 7 conditions. It could be easy with table redesign.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply