November 13, 2009 at 3:03 am
I have a table
empid date shift1 shift2
1 12/11/2009 first second
1 13/11/2009 first second
2 12/11/2009 first second
now i want the table to show as
empid date(12/11/2009) date(13/11/2009)
1 shift1 and Shift2 shift1 And shift2
is it possible to get this.
could someone help me?
thanks in advance.
November 13, 2009 at 3:55 am
Please see the links in my signature regarding Croos Tab and Dynamic Cross tab.
If you need further assistance please provide sample data in a ready to use format as described in the first link below.
Also, please consider to provide sample data that cover your scenario (using your sample it looks like shift1 and shift2 will always have the same value for each row...).
Side note: You might want to consider normalizing this table. What would happen if you need to add a third shift?
November 13, 2009 at 4:37 am
I have attached the sample data and the required table.
November 13, 2009 at 9:45 am
sudarsanan.kaliyamurthy (11/13/2009)
I have attached the sample data and the required table.
Well, doesn't really look like it...
A table definition would be something along CREATE TABLE... and sample data would be INSERT INTO ... SELECT UNION ALL.
Please help us help you by providing ready to use data so we can work on the solution and not spending too much time to set up the sample data.
November 13, 2009 at 11:09 am
sudarsanan.kaliyamurthy (11/13/2009)
I have attached the sample data and the required table.
You'll be amazed at how quickly you'll get an answer if you study the link that Lutz directed you to and post the CREATE TABLE statement along with readily consumable data using the methods in that article.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 13, 2009 at 11:19 am
Hi all,
I have attached a sample data.
Please help!!!
November 13, 2009 at 12:12 pm
Well, we're getting closer...
Following please find a proposal:
SET dateformat dmy
SELECT Emp_Id,
MAX(CASE
WHEN [Shift_Date] = '12/11/2009'
THEN ISNULL(Shift_Regular,'')
+ CASE
WHEN Shift_OnCall IS NOT NULL
THEN ' and ' +ISNULL(Shift_Regular,'')
ELSE ''
END
ELSE ''
END
) AS '11/12/2009',
MAX(CASE
WHEN [Shift_Date] = '12/11/2009'
THEN ISNULL(Shift_Regular,'')
+ CASE
WHEN Shift_OnCall IS NOT NULL
THEN ' and ' +ISNULL(Shift_Regular,'')
ELSE ''
END
ELSE ''
END
) AS '12/11/2009',
MAX(CASE
WHEN [Shift_Date] = '13/11/2009'
THEN ISNULL(Shift_Regular,'')
+ CASE
WHEN Shift_OnCall IS NOT NULL
THEN ' and ' +ISNULL(Shift_Regular,'')
ELSE ''
END
ELSE ''
END
) AS '13/11/2009',
MAX(CASE
WHEN [Shift_Date] = '14/11/2009'
THEN ISNULL(Shift_Regular,'')
+ CASE
WHEN Shift_OnCall IS NOT NULL
THEN ' and ' +ISNULL(Shift_Regular,'')
ELSE ''
END
ELSE ''
END
) AS '14/11/2009'
FROM [Emp_Shift_Details]
GROUP BY Emp_Id
/*
Emp_Id11/12/200912/11/200913/11/200914/11/2009
1first and firstfirst and firstfirst and firstfirst
2first and firstfirst and firstfirst and first
*/
November 17, 2009 at 7:37 am
Hi Lutz,
Thanks a lot for helping me out.
Sorry for late reply.
I have attached a little bit modified query and could you please help me?
Once again thanks a lot for your assistance
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply