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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sub query help

Author  Topic 

kasaya
Starting Member

10 Posts

Posted - 2009-01-07 : 22:04:04
Hi...

this is my first post ^_^

INSERT INTO tbl (Name,Parameter, DataType,UserName,DataType)
VALUES ('name1.child',(SELECT Parameter,DataType FROM tbl2 WHERE Name = 'Chart1'),'admin','string')

can u help me fix this query ^_^

this query generates
Subqueries are not allowed in this context. Only scalar expressions are allowed.


this query will save hardcoded data and data result from the query

thanks,
KaSaYa

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-07 : 22:24:58
quote:
Originally posted by kasaya

Hi...

this is my first post ^_^

INSERT INTO tbl (Name,Parameter, DataType,UserName,DataType)
VALUES ('name1.child',(SELECT Parameter,DataType FROM tbl2 WHERE Name = 'Chart1'),'admin','string')

can u help me fix this query ^_^

this query generates
Subqueries are not allowed in this context. Only scalar expressions are allowed.


this query will save hardcoded data and data result from the query

thanks,
KaSaYa





is this what you're trying to have?

INSERT INTO tbl
(Name,Parameter, DataType,UserName,DataType)
SELECT 'name1.child', Parameter, UserName, DataType
FROM tbl2
WHERE Name = 'Chart1'

Also I added the Username column on your selection because you might have been missed it, but if you want it not to be included on your insert then replace it with ''

Hope this helps.
Go to Top of Page

kasaya
Starting Member

10 Posts

Posted - 2009-01-07 : 22:44:53
quote:

is this what you're trying to have?

INSERT INTO tbl
(Name,Parameter, DataType,UserName,DataType)
SELECT 'name1.child', Parameter, UserName, DataType
FROM tbl2
WHERE Name = 'Chart1'

Also I added the Username column on your selection because you might have been missed it, but if you want it not to be included on your insert then replace it with ''

Hope this helps.




Hi,
thanks for the reply..


it did work....

thanks a lot sir
KaSaYa
Go to Top of Page
   

- Advertisement -