SQL插入select语句

时间:2017-01-13 17:04:30

标签: c# sql select insert

我想在表调用SKU中插入4个值。在这种情况下,我想从另一个表传递一个值,而我从文本框中得到3个值。

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

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

你能建议我吗?

谢谢

2 个答案:

答案 0 :(得分:4)

您可以使用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';

答案 1 :(得分:1)

Sub x()

Dim Row1 As Long

For Row1 = 1 To 10
    Select Case True
        Case IsError(Sheet1.Cells(Row1, 1)), Sheet1.Cells(Row1, 1) = vbNullString
        'do something
    End Select
Next Row1

End Sub