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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Data printing format

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-01-21 : 22:28:43
No of Columns should b:6
Table Structure:(3 set of 1234,4 set of 1234567 and so on..)
table name Style:
1
2
3
4
1
2
3
4
1
2
3
4
-----
The abovc format should be printed like given below in another new table.
max columns should be 6,
123412
341234

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-21 : 22:36:53
You have to provide more information for us to help you.

Table structure, sample data & the result you want will be very much help.


KH

Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-01-21 : 22:49:29
Result i want is:
In new table[stylenew] i want to write like the below:
col1 col2 col3 col4 col5 col6
1 2 3 4 1 2
3 4 1 2 3 4

incase if my old-table(style) contains like:
col1
1
2
3
4
5
6
7
1
2
3
4
In new table[stylenew] i want to write like the below:
col1 col2 col3 col4 col5 col6
1 2 3 4 5 6
7 1 2 3 4 5
6 7



Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-01-21 : 23:19:20
Not what khtan meant... We need to know things like what is the PK of the table, what is it's data type, and some example data to go along with the col1 example you've already shown? Otherwise, this is impossible because data is not necessarily stored in a predictable order in the database.

--Jeff Moden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-21 : 23:37:37
Jeff is right. Based on what you given, i can only come up with this. It may not be what you actually want. Do post back and explain more in detail.


drop table #old
drop table #new

-- create table for tesitng
create table #old
(
col1 int
)

create table #new
(
col1 int,
col2 int,
col3 int,
col4 int,
col5 int,
col6 int
)

-- insert data into old table
insert into #old
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 1 union all
select 2 union all
select 3

-- Old table
select * from #old

-- create an identity column for grouping & ordering
alter table #old add row int identity(0,1)
go

-- Insert into new table
insert into #new (col1, col2, col3, col4, col5, col6)
select --r = row / 6,
col1 = max(case when row % 6 = 0 then col1 end),
col2 = max(case when row % 6 = 1 then col1 end),
col3 = max(case when row % 6 = 2 then col1 end),
col4 = max(case when row % 6 = 3 then col1 end),
col5 = max(case when row % 6 = 4 then col1 end),
col6 = max(case when row % 6 = 5 then col1 end)
from #old
group by row / 6
--order by r

-- New Table
select * from #new



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-21 : 23:48:53
Just notice the thread title "Data printing format".

What you want is it only for printing or displaying on your front end application ?


KH

Go to Top of Page
   

- Advertisement -