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.
Author |
Topic |
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-11-08 : 07:02:35
|
hi,tableA:pkid caseid userid 1 1 100 2 1 200 tableB:pkid caseid userid casename1 1 100 abcill have to get the caseid based on the userid from the tableb and then join this caseid of Table B with the case id of TableA.if i do so ill get something likecaseid casename userid1 abc 1001 abc 200am i right if i left join it?but actaully i require output i want to merge this as likecaseid casename userid1 abc 100;200how to achive this. |
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-08 : 07:19:08
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=152179PBUH |
 |
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-11-08 : 07:34:43
|
quote: Originally posted by Sachin.Nand http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=152179PBUH
please send meworking sql for this. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-08 : 07:44:28
|
[code]DECLARE @MyData TABLE( OrderID INT NOT NULL, OrderItem INT NOT NULL, PersonaliseItem INT NOT NULL, PersonaliseID INT NOT NULL, OrderValue VARCHAR(100) NULL)INSERT INTO @MyDataSELECT 10372, 1, 1, 10116, 'xxx' UNION ALLSELECT 10372, 3, 9, 10031, 'Value1' UNION ALLSELECT 10372, 3, 9, 10032, 'Value2' UNION ALLSELECT 10372, 3, 10, 10037, 'Value3' UNION ALLSELECT 10372, 3, 10, 10038, NULL UNION ALLSELECT 10372, 3, 12, 10059, NULL UNION ALLSELECT 10372, 3, 12, 10064, 'Value4'SELECT *FROM @MyDataSELECT OrderID, OrderItem, (SELECT OrderValue + ','FROM @MyData xm where xm.OrderID = a.OrderID and xm.OrderItem = a.OrderItemFOR XML PATH ('')) as valFROM @MyData aGROUP BY OrderItem, OrderID[/code]PBUH |
 |
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-11-08 : 08:23:06
|
thanks |
 |
|
|
|
|
|
|