1
insert into
   [Client].[generalcontact_info]([userid], [first_name], [last_name],
                                  [email], [mobile],
                                  [country], [state], [city], [address],
                                  [Case_id], [contact_type], [query]) 
   select 
       [userid], [first_name], [last_name],
       [email], [mobile],
       [country], [state], [city], [address] 
   from 
       [Admin].[basicinfo] 
   where 
       [userid] = 100003

,'4521r521','Inside','what is my password'

我从选择语句中获取一些价值,并从我自己的代码中获取休息 id

有可能吗?

4

2 回答 2

1

是的,当然这是可能的 -SELECT用于插入的值可以在其值列表中同时包含列和“常量”:

insert into
   [Client].[generalcontact_info]([userid], [first_name], [last_name],
                                  [email], [mobile],
                                  [country], [state], [city], [address],
                                  [Case_id], [contact_type], [query]) 
   select 
       [userid], [first_name], [last_name],
       [email], [mobile],
       [country], [state], [city], [address],
       '4521r521', 'Inside', 'what is my password'
   from 
       [Admin].[basicinfo] 
   where 
       [userid] = 100003
于 2012-05-29T10:32:16.467 回答
0

你可以这样做

insert into table (col1, col2, col3)
select col1, 'static_value', col2
from table2

不要把你的值不是来自选择之后的选择。将其与选择混合。

于 2012-05-29T10:29:15.900 回答