SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert multiple rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  02:38:18  Show Profile  Reply with Quote
Hi.

I use MS SQL Compact database server v3.5

So I try to instert multiple rows in one Insert query. I get errer 25501.

It works fine with one row like this:

'INSERT INTO myTable VALUES ($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$')

But this fails:
'INSERT INTO myTable VALUES ($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$'),($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$'),($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$')'

What could be wrong?

Thanks!



Regards
Hans

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/18/2013 :  02:54:07  Show Profile  Reply with Quote
I think there is no such kind of INSERT in SQL Server Compact...
You can use insert....select values from anotherTable
Follow this link
http://msdn.microsoft.com/en-us/library/ms174633(v=sql.105).aspx

--
Chandu
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/18/2013 :  02:59:14  Show Profile  Reply with Quote
You can follow this kind of approach...
INSERT INTO YourTable
SELECT values
UNION ALL
SELECT values
UNION ALL
SELECT values
UNION ALL
SELECT values


--
Chandu
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  03:58:02  Show Profile  Reply with Quote
I did try this, same error:

'INSERT INTO myTable SELECT ($'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$') UNION ALL, SELECT ($'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$')'

Any more tip?

Regards
Hans
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/18/2013 :  04:27:17  Show Profile  Reply with Quote
Remove that comma....
INSERT INTO myTable
SELECT ($'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$')
UNION ALL,
SELECT ($'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$')

--
Chandu
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  05:15:20  Show Profile  Reply with Quote
I did try that, same result, same error

Regards
Hans
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/18/2013 :  05:53:00  Show Profile  Reply with Quote
INSERT INTO myTable
SELECT $'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$'
UNION ALL
SELECT $'2013.4.18 10:40:41:781$',$'FALSE$',$'FALSE$',$'FALSE$'


--
Chandu
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/18/2013 :  06:06:14  Show Profile  Reply with Quote
What is this $ sign for?

What error are you getting?

Cheers
MIK
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  08:45:52  Show Profile  Reply with Quote
Latest suggestion from Chandu gave error:

26306

SSCE_M_QP_COERSIONERROR

Data conversion failed.

OLE DB status value (if known)

Not applicable

On the privious one I got:

25501

SSCE_M_QP_BADPARSE

There was an error parsing the query.

Token line number, Token line offset

Token in error


Regards
Hans
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  08:47:31  Show Profile  Reply with Quote
The $ signs is for using a variable as a parameter. This works fine.

So it works fine when I just add one row, but I cant make it with multiple rows..

Regards
Hans
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 04/18/2013 :  08:54:47  Show Profile  Reply with Quote
Sorry guys, I found the problem. The last syntax suggestion from Chandu did work. I had a copy paste fault in the column definition type.

Thank you for excelent help!

Regards
Hans
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/18/2013 :  09:06:55  Show Profile  Reply with Quote
I see, havn't used SS Compact edition. in standard/enterprise its "@" sign which is used with variables and perhaps can be changed via editor settings as well.

Anyhow, if its the sign used with variable then there should have been values variables e.g. $paramter1,$parameter2, rather I see constant values?

Both errors you mentioned are Engine related. Also, are you executing this query in management studio (SSMS)? or Passed via application or some other tool to the DB engine

Try if you can execute the same query in below format

INSERT INTO Table VALUES ($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$')
INSERT INTO Table VALUES ($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$')
INSERT INTO Table VALUES ($'2013.4.18 9:21:0:906$',$'FALSE$',$'FALSE$',$'FALSE$')



Cheers
MIK
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/19/2013 :  00:30:48  Show Profile  Reply with Quote
quote:
Originally posted by hapetter

The last syntax suggestion from Chandu did work. I had a copy paste fault in the column definition type.
Thank you for excelent help!

Welcome


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000