?
Solved

SQl 2000 -  Insert  Query

Posted on 2014-01-20
8
Medium Priority
?
595 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

752 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