Groups | Blog | Home
all groups > sql server new users > october 2006 >

sql server new users : SQL 2000 dynamic query


Arnie Rowland
10/18/2006 3:05:01 PM
Your query isn't quite right. Try something on the order of:

INSERT INTO ProductInfo ( ProgramName )
SELECT ProductName
FROM ProductInfo
WHERE Product_ID =3D 21

--=20
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.=20
Most experience comes from bad judgment.=20
- Anonymous


[quoted text, click to view]
Warren Brunk
10/18/2006 4:01:14 PM
You could use a select into statement...

select * into productinfo
From ProductInfo
Where Product_ID = 21

thanks,

--
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
Tech Blog - www.technologyis.com
*/


[quoted text, click to view]

venkat
10/18/2006 5:11:48 PM
Hi,

I am trying to migrate some data from dev db to prod db.
I am trying to do this by creating queries in query analyzer like

SET QUOTED_IDENTIFIER OFF
select "Insert into productinfo (programname) values ('" + productname from
productinfo where product_id=21 + "')"

I am getting
Syntax error converting the varchar value '')' to a column of data type int

I am not sure what i am doing wrong? can someone help.

Thanks
venkat

venkat
10/19/2006 9:32:56 AM
Thanks for the feedback.,
But my idea is to generate the sql queries in query analyzer.
Basically i need to create multiple insert queries like
"Insert into productinfo (programname) values ('test1')"
"Insert into productinfo (programname) values ('test2')"

using the below query:
select "Insert into productinfo (programname) values ('" + productname
from productinfo where cat_id=21 + "')" -- Cat_id with 21 will
return multiple productnames

But i am getting an error near the "')", coz cat_id is an integer and
proceeds by a closed paranthesis.

Can it be acheived in query analyzer rather than writing a stored proc and
executing it.

Thanks
Ganesh

[quoted text, click to view]

Warren Brunk
10/19/2006 9:42:26 AM
What you need is an insert with select then...

Insert Into ProductInfo(ProgramName)
Select ProgramName From
Product Info where Cat_ID = 21


thanks,
--
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
Tech Blog - www.technologyis.com
*/


[quoted text, click to view]

Arnie Rowland
10/19/2006 9:46:24 AM
;-)

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


[quoted text, click to view]

venkat
10/19/2006 1:58:48 PM
The below one worked for me.

select 'Insert into productinfo (programname) values (''' + productname +
''')'
from productinfo where cat_id=21

Thanks guys for your help.

[quoted text, click to view]

AddThis Social Bookmark Button