Solved

SQl 2000 -  Insert  Query

Posted on 2014-01-20
8
590 Views
Last Modified: 2014-01-21
SQL SERVER 2000 - I have table :

DECLARE @Output TABLE( Name1 Varchar(255) NULL , NUM1 Varchar(255) NULL , TRAINOR1 Varchar(255) NULL,
                                          Name2 Varchar(255) NULL , NUM2 Varchar(255) NULL , TRAINOR2 Varchar(255) NULL ,
                                          Name3 Varchar(255) NULL , NUM3 Varchar(255) NULL , TRAINOR3 Varchar(255) NULL);



I want to Insert data that will spans across multiple columns like show below:

Name1  Num1    TrainOr1        Name2  Num2    TrainOr2     Name3    Num3    TrainOr3
5:00 AM - 3:00 PM Mon-Thu    3:00 PM - 1:00 AM Mon-Thu  9:00 PM - 7:00 AM Mon-Thu


Any idea?

Thanks
0
Comment
Question by:mani_sai
  • 5
  • 2
8 Comments
 
LVL 8

Author Comment

by:mani_sai
ID: 39794605
String1:  5:00 AM - 3:00 PM Mon-Thu

String2: 3:00 PM - 1:00 AM Mon-Thu

String3: 9:00 PM - 7:00 AM Mon-Thu

each strings should span 3 columns...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39794624
will you have 1 single row to be filled, or several?
where does the data come from, actually? another table? excel? ...
do you have
what exactly goes into which column? from the data/sample/column names it's not clear.

please clarify.
0
 
LVL 8

Author Comment

by:mani_sai
ID: 39794651
Data is coming from this query:

SELECTSM.Schedule
FROM dbo.ShiftManage SM , dbo.EmployeeInfo EI
Where SM.MgrNum = EI.NUM AND SM.[Group]= 'PRODUCTION'

it will be single row always..
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 8

Author Comment

by:mani_sai
ID: 39794902
sorry if I confuse you more...

all I want to know whether it is possible to insert data that will span across multiple columns...

for e.g:

Table (Col1, Col2, Col3 ,Col4,   Col5,  Col6)

I want to insert SampleData that will span across multiple columns..

Col1  Col2  Col3   Col4   Col5  Col6
SampleData1         SampleData2


If possible please let me know..

Thanks
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39795009
sure it is possible... it might be "tricky", but not impossible.
but, as I wrote above, it must be clarified how exactly the "input" data has to be "split".
what are the rules (first, in human language !)

note: if you wanted to have actually the data to be "merged", like in Excel, over several columns: that is NOT possible in a database.
0
 
LVL 8

Author Comment

by:mani_sai
ID: 39795042
SELECT  SM.Schedule
FROM dbo.ShiftManage SM , dbo.EmployeeInfo EI
Where SM.MgrNum = EI.NUM AND SM.[Group]= 'PRODUCTION'

Schedule
5:00 AM - 3:00 PM Mon-Thu
3:00 PM - 1:00 AM Mon-Thu
9:00 PM - 7:00 AM Mon-Thu

----------------------------------------------

I want to lay the data in this format:

Name1  Num1    TrainOr1        Name2  Num2    TrainOr2     Name3    Num3    TrainOr3
5:00 AM - 3:00 PM Mon-Thu    3:00 PM - 1:00 AM Mon-Thu  9:00 PM - 7:00 AM Mon-Thu

--------------------------------------------
0
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 39796205
What is your problem?
1) Wanting rusult of column Name1 span unther the titles of the 2 next columns?
Name1  Num1    TrainOr1
5:00 AM - 3:00 PM Mon-Thu
In what circumstances?  
Guess  concatinate titles an column content to make it one virtual column tackles your problem

2) Pivot result
Name1  Num1    TrainOr1        Name2  Num2    TrainOr2     Name3    Num3    TrainOr3
5:00 AM - 3:00 PM Mon-Thu    3:00 PM - 1:00 AM Mon-Thu  9:00 PM - 7:00 AM Mon-Thu
SQL2000 lacks a lot of functionality that can be usefull

Trick is to get a number 1,2,3 to your result to know where it should result. A temp-table with a identity-column is a possibility.
Then something like this could be a solution
select (max(x.name1),max(x.name2)
from
 (select case when rownumid=1 then shedule else null end  as Name1,null as name2
 union select null as name1,case when rownumid=2 then shedule else null end  as Name2
 ) as x

Open in new window

0
 
LVL 8

Author Comment

by:mani_sai
ID: 39798402
Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now