日期:2014-05-18  浏览次数:20515 次

一简单SQL请加大帮忙改改!在insert语句中使用select,而select中要组合字符串
在insert语句中使用select不?我想把ProductID,ProductName   组合在一个查询中作

insert   into   T_LeaguerOrderDetail(SerialNumber,OrderID,ProductID,ProductName,
ProductPrice,ProductNumber,OperatingPersonnel)  
values  
( 'wang520d ', '123 ', '2562 ',
select   Convert(varchar,productName)   +   ', '   +   Convert(varchar,actressprice)     from   T_Product_List   where   Listid   =2562
,
123, 'wang520d ')


------解决方案--------------------
insert into T_LeaguerOrderDetail(SerialNumber,OrderID,ProductID,ProductName,ProductPrice,ProductNumber,OperatingPersonnel)
select 'wang520d ', '123 ', '2562 ',Convert(varchar,productName) + ', ' + Convert(varchar,actressprice),123, 'wang520d ' from T_Product_List where Listid =2562

------解决方案--------------------
insert into T_LeaguerOrderDetail
(SerialNumber,OrderID,ProductID,ProductName,ProductPrice,ProductNumber,OperatingPersonnel)
select 'wang520d ', '123 ', '2562 ',cast(productName as varchar) + ', ' + cast(actressprice as varchar),123, 'wang520d ' from T_Product_List where Listid = 2562

------解决方案--------------------
你想实现什么啊?
declare @ProName varchar 50;
declare @ProPri varchar 50;
select @PruName=Convert(varchar,productName) ,@ProPri=
Convert(varchar,actressprice) from T_Product_List where Listid =2562;
insert into T_LeaguerOrderDetail(SerialNumber,OrderID,ProductID,ProductName,
ProductPrice,ProductNumber,OperatingPersonnel)
values
( 'wang520d ', '123 ', '2562 ',@PruName,@ProPri,123, 'wang520d ')
------解决方案--------------------
insert into T_LeaguerOrderDetail
(SerialNumber,OrderID,ProductID,ProductName,ProductPrice,ProductNumber,OperatingPersonnel)
select 'wang520d ', '123 ', '2562 ',cast(productName as varchar) , cast(actressprice as varchar),123, 'wang520d ' from T_Product_List where Listid = 2562