Say I have a query that inserts using a select as such: Code: INSERT INTO courses name, location, gid SELECT (name, location, gid) FROM courses WHERE cid = $cid Is it possible to only select "name,location" for the insert, and set gid to something else in the query? Thanks in advance
You can do it in different ways as specified below… You can declare a variable and provide @var in place of GID in select statement Declare @var varchar (100) Iset @var = ‘value’ INSERT INTO courses name, location, gid SELECT (name, location, @var) FROM courses WHERE cid = $cid You can send any static value in place of GID in select statement like below example… INSERT INTO courses name, location, gid SELECT (name, location, ‘Value’) FROM courses WHERE cid = $cid You can write a select statement in select statement for getting GID value INSERT INTO courses name, location, gid SELECT (name, location, (select x from y )) FROM courses WHERE cid = $cid You want to do it separately than it will be a update statement after insert statement these all queries are in TSQL