Reputation: 345
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'
I am taking some value from select statement and rest id from my own code
is it possible to do?
Upvotes: 1
Views: 174
Reputation: 755541
Yes of course it's possible - the SELECT
used to insert can have both columns as well as "constants" in its list of values:
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
Upvotes: 1
Reputation: 204924
You can do that like this
insert into table (col1, col2, col3)
select col1, 'static_value', col2
from table2
Don't put your values not coming from the select after the select. Mix it with the select.
Upvotes: 0