Jump to content

Sql server 2000 Help


Pradyumna

Recommended Posts

Hi, I am pradyumna.I am using ms sql server 2000 .I am trying to insert two records at a time in a table.I try the quary : Insert into pradyumna values('pk',2000,'india') (it is one row insert)But i am trying two records at a time: Insert into pradyumna values('pk',2000,'india');('sk',12000,'USA')

Link to comment
Share on other sites

The syntax you are using is not corret. To save you some "typing work" you can use :

INSERT INTO pradyumna(field1,field2,field3) SELECT 'pk','2000','india'UNION ALLSELECT 'sk','12000','USA'

Link to comment
Share on other sites

I am not aware of anyway to do it with that type of syntax - I beleive you must write the insert statement each time.

Insert into pradyumna values('pk',2000,'india')Insert into pradyumna values('sk',12000,'USA')
Link to comment
Share on other sites

I actually was discussing this with a developer earlier today for something I was doing. There is no way to do this without rewriting the query each time (I am interested though in trying Jerome's method).Well, from what the developer told me, you can do it with a loop and a bunch of if statements, its not pretty but can reduce the number of queries and error handling routines needed. Basically you would do:

Count = 0Do    If count = 1        set variables    If count = 2        set variables appropriately...Hope you see where this is going    Use the query with variables rather than constants    Inert error handling    Count = Count + 1While (count < Pre-defined number)

This is by no means the correct syntax, merely the pseudo code of what you could do using Transact-SQL.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...