October 17, 2007 at 2:35 am
hi,
Can you please help me in this issue?
create table #check
(
cno int ,
sal int default(200)
)
--------
insert into #check
values (1, default)
above query is working but below query is not working.
insert into #check
select 1, default
why So?
My Question : Is it not possible to insert default value by select?
Cheers!
Sandy.
--
October 17, 2007 at 3:23 am
it's like with select: avoid implicit column references. if order of columns in your table changes, inserts may fail and it can be hard to track.
this query works and it inserts default value to sal field:
insert into #check (cno)
select 2
...and your only reply is slàinte mhath
October 17, 2007 at 3:32 am
Hey Piotr Rodak,
Thanks A Lot.
Cheers!
🙂
Sandy.
--
October 17, 2007 at 3:33 am
Hi Sandy,
Piotr is right with the solution of removing the default from the select. The select statement should execute on its own when its result is used to put into another table. "select 1, default" is not a statement that is syntactically valid. Once you have got a statement that returns the expected result, you can use it in an insert statement, and can remap the columns.
Andras
October 17, 2007 at 3:37 am
Thanks Andras,
For your quick reply,
Cheers!
Sandy.
--
October 18, 2007 at 7:53 am
insert into has to be from exsiting table.
get any existing table, select 2 fields and hardcode it.
Insert into #check
select 1 Column1, default Column1 from tbl1
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply