user6453809 user6453809 - 1 year ago 85
SQL Question

Cast with multiple select

I need to select from multiple tables. in one of two tables i use cast. So my code is look like below:

insert into TEST (id,name) (SELECT (MAX(id) + 1), (select 'NEW-1-'+CAST((MAX(id) + 1) AS VARCHAR(10)) from test)

I get an error with incorrect syntax

Answer Source

So from my understanding the piece of code you have...

 select 'New-1-'+CAST((MAX(ID) + 1) AS VARCHAR(10))

currently works? But you are having trouble with...

 (SELECT (MAX(id) + 1), (select 'new-1-'+CAST((MAX(id) + 1) AS VARCHAR(10)) from test

So the issue you are having is with multiple selects. You don't do multiple selects. You can just keep typing them with commas in-between like so...

 SELECT (MAX(id) + 1), 'new-1-'+CAST((MAX(id) + 1) AS VARCHAR(10)) from test

This should be what you are looking for. Please comment this answer if you have any questions and try to answer my follow up questions through your original question :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download