[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQl 2000 -  Insert  Query

Posted on 2014-01-20
8
Medium Priority
?
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

650 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