Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert multiple rows

Author  Topic 

hapetter
Starting Member

10 Posts

Posted - 2013-04-18 : 02:38:18
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-18 : 02:54:07
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-18 : 02:59:14
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 - 2013-04-18 : 03:58:02
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-18 : 04:27:17
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 - 2013-04-18 : 05:15:20
I did try that, same result, same error

Regards
Hans
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-18 : 05:53:00
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
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-04-18 : 06:06:14
What is this $ sign for?

What error are you getting?

Cheers
MIK
Go to Top of Page

hapetter
Starting Member

10 Posts

Posted - 2013-04-18 : 08:45:52
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 - 2013-04-18 : 08:47:31
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 - 2013-04-18 : 08:54:47
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
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-04-18 : 09:06:55
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-19 : 00:30:48
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
   

- Advertisement -