Solved

SQl 2000 -  Insert  Query

Posted on 2014-01-20
8
584 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Assistance 4 31
Database Containment - Benefits 6 26
Sql query 34 22
Query to Add Late Tolerance 10 31
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

762 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

21 Experts available now in Live!

Get 1:1 Help Now