3

Received a query in this format for a data import...is there any equivelent in TSQL where you would only have to use "insert into blah" once? (so that I can convert this script)

insert into marital_status (id,description) 
values
   (1,'Married'),
   (2,'Separated'),
   (3,'Never Married'),
   (4,'Divorced'),
   (5,'Widowed'),
   (6,'Co-Habitation'),
   (7,'No Response')

2 Answers 2

5

This is a T-SQL script - for Server 2008 - unforutnately, in 2005, you don't have this feature available :-(

You need to write this query like this:

insert into marital_status (id,description) 
values(1,'Married')
insert into marital_status (id,description) 
values(2,'Separated')
insert into marital_status (id,description) 
values(3,'Never Married')
insert into marital_status (id,description) 
values(4,'Divorced')
insert into marital_status (id,description) 
values(5,'Widowed')
insert into marital_status (id,description) 
values(6,'Co-Habitation')
insert into marital_status (id,description) 
values(7,'No Response')
Sign up to request clarification or add additional context in comments.

1 Comment

ah...Still on 2005 so I'm not as familiar with the latest TSQL as I would like to be. This is the type of answer I thought I would get...thanks.
3

Another alternative would be:

insert into marital_status (id,description) 
    SELECT 1,'Married'       UNION ALL
    SELECT 2,'Separated'     UNION ALL
    SELECT 3,'Never Married' UNION ALL
    SELECT 4,'Divorced'      UNION ALL
    SELECT 5,'Widowed'       UNION ALL
    SELECT 6,'Co-Habitation' UNION ALL
    SELECT 7,'No Response'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.