milani_lucie
asked on
ETL command help needed !!
Hi,
I have the following data:
A
B
C
D
I want to convert this data like this
A B C D
Can you provide me the basic SQL command needed for this ?
Thanks
I have the following data:
A
B
C
D
I want to convert this data like this
A B C D
Can you provide me the basic SQL command needed for this ?
Thanks
ASKER
Please provide me the command. This is not PIVOT/UNPIVOT related.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I want to show the ROWS as COLUMNS. I think so your query does not return that way. Am i correct ?
Thanks
Thanks
>I want to show the ROWS as COLUMNS.
well, that IS pivoting, resp crosstab.
if you want all your rows to be pivoted to columns, is being a special case, nevertheless it is called that way.
however, standard pivot statement will not do the job, though.
now, can you explain why you want that to be done?
eventually, you want to do this more effectively in the application?
well, that IS pivoting, resp crosstab.
if you want all your rows to be pivoted to columns, is being a special case, nevertheless it is called that way.
however, standard pivot statement will not do the job, though.
now, can you explain why you want that to be done?
eventually, you want to do this more effectively in the application?
ie, you might want to give more information about the "big picture"...
as angeliii say unless you can tell us what the structure of your data is there is no way we can assist in the conversion you desire.
there must be structure to your data to enable use to process it as you require...
no sql statements on there own can guarantee that
any 4 rows of data can be consistently combined
from
a
b
c
d
into
a b c d
unless there is some ordering information that is "embedded" into the data...
are you wanting the data sorted into ascending order and then converted into
rows containing the data in ascending column order?
if not explain what the sequence will be ....
you may need to do you conversion in a standard programming language external to sql ...
SQL can only consistently process "Sets"
there must be structure to your data to enable use to process it as you require...
no sql statements on there own can guarantee that
any 4 rows of data can be consistently combined
from
a
b
c
d
into
a b c d
unless there is some ordering information that is "embedded" into the data...
are you wanting the data sorted into ascending order and then converted into
rows containing the data in ascending column order?
if not explain what the sequence will be ....
you may need to do you conversion in a standard programming language external to sql ...
SQL can only consistently process "Sets"
ASKER
Here is what i mean:
USE Sample
GO
-- Create a table
CREATE TABLE T
(
X int,
Y int,
Z int
)
GO
-- Insert some sample data
INSERT INTO T VALUES (1, 2, 3)
GO
-- Select the contents
SELECT X, Y, Z
FROM T
GO
-- Column As Row
SELECT 'X' AS 'Source', X AS 'Value' FROM T
UNION ALL
SELECT 'Y' AS 'Source', Y AS 'Value' FROM T
UNION ALL
SELECT 'Z' AS 'Source', Z AS 'Value' FROM T
GO
I need just opposite to this
USE Sample
GO
-- Create a table
CREATE TABLE T
(
X int
)
GO
-- Insert some sample data
INSERT INTO T VALUES (1)
GO
INSERT INTO T VALUES (2)
GO
INSERT INTO T VALUES (3)
GO
-- Select the contents
SELECT X
FROM T
GO
-- Row As Column
Please provide me code here.
Thanks
USE Sample
GO
-- Create a table
CREATE TABLE T
(
X int,
Y int,
Z int
)
GO
-- Insert some sample data
INSERT INTO T VALUES (1, 2, 3)
GO
-- Select the contents
SELECT X, Y, Z
FROM T
GO
-- Column As Row
SELECT 'X' AS 'Source', X AS 'Value' FROM T
UNION ALL
SELECT 'Y' AS 'Source', Y AS 'Value' FROM T
UNION ALL
SELECT 'Z' AS 'Source', Z AS 'Value' FROM T
GO
I need just opposite to this
USE Sample
GO
-- Create a table
CREATE TABLE T
(
X int
)
GO
-- Insert some sample data
INSERT INTO T VALUES (1)
GO
INSERT INTO T VALUES (2)
GO
INSERT INTO T VALUES (3)
GO
-- Select the contents
SELECT X
FROM T
GO
-- Row As Column
Please provide me code here.
Thanks
milani_lucie, my request must be look like a pain, but I repeat:
you provided SQL of what you think you want, please provide the "big picture" of what you are trying to achieve.
explaining with a dummy 1 table 1 column will not help us understand why you don't want to take the crosstab procedures available on the net, for example:
http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1131829,00.html
you said that you don't want to "PIVOT", still the method of getting rows into columns is called so.
you provided SQL of what you think you want, please provide the "big picture" of what you are trying to achieve.
explaining with a dummy 1 table 1 column will not help us understand why you don't want to take the crosstab procedures available on the net, for example:
http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1131829,00.html
you said that you don't want to "PIVOT", still the method of getting rows into columns is called so.
http://articles.techrepublic.com.com/5100-9592-6143761.html
http://technet.microsoft.com/en-us/library/ms177410.aspx