简体   繁体   English

SQL插入选择语句

[英]SQL insert select statement

I want to insert 4 values in the table call SKU. 我想在表调用SKU中插入4个值。 In this case I want to pass one value from another table while I have 3 value from the text box. 在这种情况下,我想从另一个表传递一个值,而我在文本框中有3个值。

insert into [dbo].[Sku] (skuid, clientid, skudesc, [Type]) 
values (test, clientid, test, physical)

select Clientid 
from [dbo].[Client] 
where clientname like 'Admin';

Could you please suggest me? 你能建议我吗?

Thank you 谢谢

you can use insert into .. select .. syntax, but the values you want to get from the text box needs to be as part of the select clause: 您可以insert into .. select ..语法中使用insert into .. select .. ,但是要从文本框中获取的值必须作为select子句的一部分:

insert into [dbo].[Sku] (skuid,clientid,skudesc,[Type])  
  select 'test' as skuid, clientid, 'test' as skudesc, 'physical' as [type]
  from [dbo].[Client] where clientname like 'Admin';
    Create procedure procName
    (
        @test int,
        @clientid int
    )
    As
    Begin

    insert into [dbo].[Sku] (skuid,clientid,skudesc,[Type]) 
    values (@test,@clientid,@test,
    (select Clientid from [dbo].[Client] where clientname   like 'Admin'))

    End

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM