Question : How to retrieve ONLY the column I need from a select statement

Hi,

I have a SELECT statement but at the moment it brings back all columns relating to the day it retrieves. Below is the SELECT statement. What I would like to do is only retrieve the data for the day I am retrieving for; so, if I run this and it's Wednesday, I only want each of these to bring back Wednesdays column. Is there a way to do this and also to make the column retrieved just say DCS1, DCS2, DCS3, DCS4 instead of the week day in front of it?

Any help would be much appreciated.

Regards,

Ken


SELECT     countryCode, cityCode, itemCode, storeType, vendorCode, gridCodeX, gridCodeY, facings, brand, rc, storeCode, storeName,ARABIC, ItemName, upcCode, TREF,
                      satDCS1, sunDCS1, monDCS1, tueDCS1, wedDCS1, thuDCS1, friDCS1, satDCS2, sunDCS2, monDCS2, tueDCS2, wedDCS2, thuDCS2, friDCS2,
                      satDCS3, sunDCS3, monDCS3, tueDCS3, wedDCS3, thuDCS3, friDCS3, satDCS4, sunDCS4, monDCS4, tueDCS4, wedDCS4, thuDCS4, friDCS4
FROM         dbo.ScheduleView
WHERE     (CASE DATEPART(weekday, @date )
                      WHEN 1 THEN [SunDCS1] WHEN 2 THEN [MonDCS1] WHEN 3 THEN [TueDCS1] WHEN 4 THEN [WedDCS1] WHEN 5 THEN [ThuDCS1] WHEN 6 THEN [FriDCS1] WHEN 7 THEN
                       [SatDCS1] END = 1)
                       OR
                       (CASE DATEPART(weekday, @date )
                      WHEN 1 THEN [SunDCS2] WHEN 2 THEN [MonDCS2] WHEN 3 THEN [TueDCS2] WHEN 4 THEN [WedDCS2] WHEN 5 THEN [ThuDCS2] WHEN 6 THEN [FriDCS2] WHEN 7 THEN
                       [SatDCS2] END = 1)
                        OR
                       (CASE DATEPART(weekday, @date )
                      WHEN 1 THEN [SunDCS3] WHEN 2 THEN [MonDCS3] WHEN 3 THEN [TueDCS3] WHEN 4 THEN [WedDCS3] WHEN 5 THEN [ThuDCS3] WHEN 6 THEN [FriDCS3] WHEN 7 THEN
                       [SatDCS3] END = 1)
                        OR
                       (CASE DATEPART(weekday, @date )
                      WHEN 1 THEN [SunDCS4] WHEN 2 THEN [MonDCS4] WHEN 3 THEN [TueDCS4] WHEN 4 THEN [WedDCS4] WHEN 5 THEN [ThuDCS4] WHEN 6 THEN [FriDCS4] WHEN 7 THEN
                       [SatDCS4] END = 1)

Answer : How to retrieve ONLY the column I need from a select statement

Apologies..
Left out the * from the inner query
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
CREATE FUNCTION dbo.fnScheduleView(@date datetime)
RETURNS TABLE AS RETURN
WITH DP AS (SELECT DP=DATEPART(weekday, @date ))
SELECT countryCode, cityCode, itemCode, storeType, vendorCode, gridCodeX, gridCodeY, facings, brand, rc, storeCode, storeName,ARABIC, ItemName, upcCode, TREF,
DSC1,DSC2,DSC3,DSC4
FROM
(
	SELECT *,
	CASE DP.DP WHEN 1 THEN [SunDCS1] WHEN 2 THEN [MonDCS1] WHEN 3 THEN [TueDCS1] WHEN 4 THEN [WedDCS1] WHEN 5 THEN [ThuDCS1] WHEN 6 THEN [FriDCS1] WHEN 7 THEN
						   [SatDCS1] END DSC1,
	CASE DP.DP WHEN 1 THEN [SunDCS2] WHEN 2 THEN [MonDCS2] WHEN 3 THEN [TueDCS2] WHEN 4 THEN [WedDCS2] WHEN 5 THEN [ThuDCS2] WHEN 6 THEN [FriDCS2] WHEN 7 THEN
						   [SatDCS2] END DSC2,
	CASE DP.DP WHEN 1 THEN [SunDCS3] WHEN 2 THEN [MonDCS3] WHEN 3 THEN [TueDCS3] WHEN 4 THEN [WedDCS3] WHEN 5 THEN [ThuDCS3] WHEN 6 THEN [FriDCS3] WHEN 7 THEN
						   [SatDCS3] END DSC3,
	CASE DP.DP WHEN 1 THEN [SunDCS4] WHEN 2 THEN [MonDCS4] WHEN 3 THEN [TueDCS4] WHEN 4 THEN [WedDCS4] WHEN 5 THEN [ThuDCS4] WHEN 6 THEN [FriDCS4] WHEN 7 THEN
						   [SatDCS4] END DSC4
FROM dbo.ScheduleView CROSS JOIN DP
) SQ
WHERE DSC1=1 OR DSC2=1 OR DSC3=1 OR DSC4=1
GO
Random Solutions  
 
programming4us programming4us