Sunday, February 19, 2012

I need HEEEEEEELP !

Hi ,
can anyone help me?
I have this Table :
Sourcetable :
ProductID (INT) | LineNo (INT) | Text (Nvarchar)
---
10015 | 10 | This is my
10015 | 12 | best item
10015 | 16 | on Stock.
10020 | 100 | An other
10020 | 110 | item
10020 | 120 | on stock.
I want to copy the rows in a new Table
For Example:
Destinationtable :
ProductID (INT) | Text (nText)
--
10015 | This is my best item on Stock.
10020 | An other item on Stock.
How to do ?Do it through access. Access is a great tool for little things like this. Of
course you can also do it through sql. Try SQL Views.
select everything
For each row in sourcetable
Check for Product ID
If it's the same as the previous row then concatenate the Text field
else
start a new row
Loop
"kepir" <kepir@.discussions.microsoft.com> wrote in message
news:C21CCADB-A127-43ED-8749-09FBCDFB3A23@.microsoft.com...
> Hi ,
> can anyone help me?
> I have this Table :
> Sourcetable :
> ProductID (INT) | LineNo (INT) | Text (Nvarchar)
> ---
> 10015 | 10 | This is my
> 10015 | 12 | best item
> 10015 | 16 | on Stock.
> 10020 | 100 | An other
> 10020 | 110 | item
> 10020 | 120 | on stock.
> I want to copy the rows in a new Table
> For Example:
> Destinationtable :
> ProductID (INT) | Text (nText)
> --
> 10015 | This is my best item on Stock.
> 10020 | An other item on Stock.
> How to do ?|||If you have a small, limited number of rows for each group, you can do:
SELECT ProductId,
MAX( CASE seq WHEN 1 THEN Text ELSE '' END ) +
MAX( CASE seq WHEN 2 THEN ' ' + Text ELSE '' END ) +
MAX( CASE seq WHEN 3 THEN ' ' + Text ELSE '' END ) +
MAX( CASE seq WHEN 4 THEN ' ' + Text ELSE '' END )
FROM ( SELECT ProductId, Text,
( SELECT COUNT( * ) FROM tbl t2
WHERE t2.ProductId = t1.ProductId
AND t2.LineNo <= t1.LineNo )
FROM tbl t1 ) D ( ProductId, Text, seq )
GROUP BY ProductId ;
As far as general approaches in the server, for SQL 2005, try:
http://groups.google.com/group/micr...br />
9b9b968a
For 2000, try:
http://groups.google.com/group/micr...br />
6dd9e73e
Alternatively, for display purposes, you could get the results out of the
server, do the massaging & apply the string manipulation functionalities of
client programming language or report writer as well.
Anith|||I need HEEEEEEELP subject is so immature. Please consider using good subject
and you will get more feedback. gee...
"kepir" <kepir@.discussions.microsoft.com> wrote in message
news:C21CCADB-A127-43ED-8749-09FBCDFB3A23@.microsoft.com...
> Hi ,
> can anyone help me?
> I have this Table :
> Sourcetable :
> ProductID (INT) | LineNo (INT) | Text (Nvarchar)
> ---
> 10015 | 10 | This is my
> 10015 | 12 | best item
> 10015 | 16 | on Stock.
> 10020 | 100 | An other
> 10020 | 110 | item
> 10020 | 120 | on stock.
> I want to copy the rows in a new Table
> For Example:
> Destinationtable :
> ProductID (INT) | Text (nText)
> --
> 10015 | This is my best item on Stock.
> 10020 | An other item on Stock.
> How to do ?|||agreed
"Grant" <email@.nowhere.com> wrote in message
news:OrJWHv9OGHA.3100@.TK2MSFTNGP11.phx.gbl...
> I need HEEEEEEELP subject is so immature. Please consider using good
subject
> and you will get more feedback. gee...
>
>
> "kepir" <kepir@.discussions.microsoft.com> wrote in message
> news:C21CCADB-A127-43ED-8749-09FBCDFB3A23@.microsoft.com...
>|||I'll answer a request for help with 7 E's before one with 5 E's.
In all seriousness, I usually ignore this kind of subject line, because I am
not sure if the poster's problem(s) involve technology in general, never
mind SQL Server specifically.|||I'm not sure we should penalize those with an 'E' key that gets stuck while
the back-space and delete keys are inoperable.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23wr7nF%23OGHA.812@.TK2MSFTNGP10.phx.gbl...
> I'll answer a request for help with 7 E's before one with 5 E's.
> In all seriousness, I usually ignore this kind of subject line, because I
> am not sure if the poster's problem(s) involve technology in general,
> never mind SQL Server specifically.
>|||Thank You Anith,
but there is a Syntax Error in Line 9. Is it possible to send me the hole
Code.
For example there is no declaration of "seq".
bye
"Anith Sen" wrote:

> If you have a small, limited number of rows for each group, you can do:
> SELECT ProductId,
> MAX( CASE seq WHEN 1 THEN Text ELSE '' END ) +
> MAX( CASE seq WHEN 2 THEN ' ' + Text ELSE '' END ) +
> MAX( CASE seq WHEN 3 THEN ' ' + Text ELSE '' END ) +
> MAX( CASE seq WHEN 4 THEN ' ' + Text ELSE '' END )
> FROM ( SELECT ProductId, Text,
> ( SELECT COUNT( * ) FROM tbl t2
> WHERE t2.ProductId = t1.ProductId
> AND t2.LineNo <= t1.LineNo )
> FROM tbl t1 ) D ( ProductId, Text, seq )
> GROUP BY ProductId ;
> As far as general approaches in the server, for SQL 2005, try:
> http://groups.google.com/group/micr... />
8a9b9b968a
> For 2000, try:
> http://groups.google.com/group/micr... />
366dd9e73e
> Alternatively, for display purposes, you could get the results out of the
> server, do the massaging & apply the string manipulation functionalities o
f
> client programming language or report writer as well.
> --
> Anith
>
>|||I′m sorry but this is my first posting . I didn′t know that this would be
a
Problem.
I do not know how to change the subject. Next Time i will do it better.
But my Problem is the same. Is there anyone can help me?
bye
"Jeff S" wrote:

> I'm not sure we should penalize those with an 'E' key that gets stuck whil
e
> the back-space and delete keys are inoperable.
>
>
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in messag
e
> news:%23wr7nF%23OGHA.812@.TK2MSFTNGP10.phx.gbl...
>
>|||Without DDLs, I did not bother to create tables & test them.
In any case, lineno & text are reserved words in SQL. It is a bad idea to
use them in usable code. Either change the column names to valid identifiers
or use delimiting characters like double quotes (") or square brackets (
[] ) around the names.
Anith

No comments:

Post a Comment