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)
 Can we have query like this?

Author  Topic 

SHIVPREET2K1
Starting Member

32 Posts

Posted - 2009-05-04 : 07:36:25
Dear all can we have a query through which we provide static and dynamic data at the same time. i mean something like this


insert into order_Table (order_no,order_Date,item_Code,detail) values('xx-1','04-05-09',Select item_Code,detail from item_Table)




i mean i have provided query as well as literal data to insert at the same time. is that possible. if yes then please tell the syntax.

other wise i have to write the logic in .net which might not be as fast as the query execution.


Thanks in advance.

ShivPreet2k1

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-05-04 : 07:38:53
insert into order_Table (order_no,order_Date,item_Code,detail) select 'xx-1','04-05-09', item_Code,detail from item_Table
Go to Top of Page

SHIVPREET2K1
Starting Member

32 Posts

Posted - 2009-05-04 : 08:00:22
thanks for your help but this query gives error

i am sending the exact query


insert into
RM_Order
(Vendor,Order_No,Item_Type,Order_Date,RM_Code,Order_Qty)
select
'DUM','ORD-1000','CASTING','04-May-09',
select material_Code , category from Raw_Material_or_Accesory_Master where category like '%CASTING%'


the error it give is

Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'select'.



if there is any thing missing then plz tell me.

thanks for your help again

Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-04 : 08:02:30
why 2 selects ?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-05-04 : 08:03:11
You can only specify SELECT once:
insert into RM_Order (Vendor,Order_No,Item_Type,Order_Date,RM_Code,Order_Qty)
select 'DUM','ORD-1000','CASTING','04-May-09', material_Code , category
from Raw_Material_or_Accesory_Master where category like '%CASTING%'
Go to Top of Page

SHIVPREET2K1
Starting Member

32 Posts

Posted - 2009-05-04 : 08:13:44
Thanks robwolk.

my problem is resolved with ur help. you know even normal tutorial on internet do not provide this kind of knowledge.

Thanks again
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-05-04 : 10:08:06
It's in Books Online, that should be your first stop for SQL Server information.
Go to Top of Page
   

- Advertisement -