SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE STATEMET
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

velvettiger
Posting Yak Master

115 Posts

Posted - 02/15/2013 :  12:31:28  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3638 Posts

Posted - 02/15/2013 :  13:06:54  Show Profile  Reply with Quote
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 - 02/15/2013 :  13:59:07  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 02/15/2013 :  14:21:29  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000