[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQl 2000 -  Insert  Query

Posted on 2014-01-20
8
Medium Priority
?
607 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 143

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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 143

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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

872 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