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
 CASE STATEMET

Author  Topic 

velvettiger
Posting Yak Master

115 Posts

Posted - 2013-02-15 : 12:31:28
Hi Guys,

I would like to output the day that a lecture classes occurs.

Now each day is stored in a separate table. Each day is stored in a separate table. The word Monday is stored in a table called SSRMEET_MON_DAY, The word Tuesdays is stored in a table called SSRMEET_TUE_DAY ETC.

I am trying to extract all days in one column to then use a where clause to determine which day should be displayed in the report.
Therefore, I would like my table to look like:
[CODE]
DAYS
Monday
Tuesday
Wednesday
Thursday


Instead of :

SSRMEET_MON_DAY SSRMEET_TUES_DAY
Monday Tuesday
[/code

And I don't have the privileges to create temporary tables.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-15 : 13:06:54
I didn't quite follow the concept of storing the word Monday in a table named SSRMEET_MON_DAY etc., nonetheless:
SELECT code FROM SSRMEET_MON_DAY UNION ALL
SELECT code FROM SSRMEET_TUE_DAY UNION ALL
SELECT code FROM SSRMEET_WED_DAY UNION ALL
....
SELECT code FROM SSRMEET_SUN_DAY
Go to Top of Page

velvettiger
Posting Yak Master

115 Posts

Posted - 2013-02-15 : 13:59:07
Hi James,

If I do the

SELECT code as DAYS
FROM SSRMEET_MON_DAY
UNION ALL
SELECT code
FROM SSRMEET_TUE_DAY
UNION ALL
SELECT code
FROM SSRMEET_WED_DAY
UNION ALL
....
SELECT code
FROM SSRMEET_SUN_DAY


Will I be able to do the following

where Days = 'Monday'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-15 : 14:21:29
yep you'll be able to do it

SELECT *
FROM
(
SELECT code as DAYS
FROM SSRMEET_MON_DAY
UNION ALL
SELECT code
FROM SSRMEET_TUE_DAY
UNION ALL
SELECT code
FROM SSRMEET_WED_DAY
UNION ALL
....
SELECT code
FROM SSRMEET_SUN_DAY
)t
WHERE DAYS ='Monday'


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

Go to Top of Page
   

- Advertisement -