May 11, 2012 at 12:17 am
I have a table with two column
out put date is like this...
mnemonicId customerID
1402 140201
1402 140202
1402 140203
now i want out put like this
mnemonicId customerID xyz
1402 140201 140202
1402 140201 140203
1402 140202 140203
so please help .....
May 11, 2012 at 12:30 am
What is the logic here?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 11, 2012 at 12:51 am
Sorry i havent any logic ....
May 11, 2012 at 1:02 am
this will do the job with the sample data provided, but if you dont know the logic then we can only guess at what you want and how it should be done.
declare @table table (mnemonicid int, customerid int)
insert into @table values (1402,140201),(1402,140201),(1402,140202)
;with cte as
(
select
mnemonicid,
customerid,
ROW_NUMBER() OVER(PARTITION BY customerid ORDER BY customerid) as RowNum
from
@table
)
select
mnemonicid,
customerid,
customerid + rownum AS xyz
from
cte
May 11, 2012 at 1:06 am
sachince61 (5/11/2012)
Sorry i havent any logic ....
Really? So any two customerIDs on the same line, like this?
mnemonicId customerID xyz
1402 140201 140202
1402 140203 140201
1402 140202 140201
?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 11, 2012 at 1:18 am
sachince61 (5/11/2012)
I have a table with two columnout put date is like this...
mnemonicId customerID
1402 140201
1402 140202
1402 140203
now i want out put like this
mnemonicId customerID xyz
1402 140201 140202
1402 140201 140203
1402 140202 140203
so please help .....
If there is no logic then why do you want to do it??...What is the business requirement behind this??
May 11, 2012 at 1:31 am
anthony.green (5/11/2012)
this will do the job with the sample data provided, but if you dont know the logic then we can only guess at what you want and how it should be done.
declare @table table (mnemonicid int, customerid int)
insert into @table values (1402,140201),(1402,140201),(1402,140202)
;with cte as
(
select
mnemonicid,
customerid,
ROW_NUMBER() OVER(PARTITION BY customerid ORDER BY customerid) as RowNum
from
@table
)
select
mnemonicid,
customerid,
customerid + rownum AS xyz
from
cte
I tried the same thing Anthony.
But then I checked out the sample data and the required result set posted by the OP and saw this difference in the last row:
mnemonicId customerID
1402 140201
1402 140202
1402 140203
now i want out put like this
mnemonicId customerID xyz
1402 140201 140202
1402 140201 140203
1402 140202 140203
May 11, 2012 at 1:37 am
vinu512 (5/11/2012)
anthony.green (5/11/2012)
this will do the job with the sample data provided, but if you dont know the logic then we can only guess at what you want and how it should be done.
declare @table table (mnemonicid int, customerid int)
insert into @table values (1402,140201),(1402,140201),(1402,140202)
;with cte as
(
select
mnemonicid,
customerid,
ROW_NUMBER() OVER(PARTITION BY customerid ORDER BY customerid) as RowNum
from
@table
)
select
mnemonicid,
customerid,
customerid + rownum AS xyz
from
cte
I tried the same thing Anthony.
But then I checked out the sample data and the required result set posted by the OP and saw this difference in the last row:
mnemonicId customerID
1402 140201
1402 140202
1402 140203
now i want out put like this
mnemonicId customerID xyz
1402 140201 140202
1402 140201 140203
1402 140202 140203
Excellent spot Vinu, I totally missed that, anyway if the OP doesnt know the logic or the business requirements to do the task then we can only speculate. One thing I would ask is that the OP follow the best practise links in our signatures on the next post with the logic so that we can help them better.
May 11, 2012 at 2:46 am
Thanks for reply....
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply