| Author |
Topic  |
|
|
ksr39
Posting Yak Master
India
171 Posts |
Posted - 11/29/2012 : 04:06:43
|
Hi Experts,
I am a SQL DBA not much used to coding (t-sql), need a small help on a insert statement.
INSERT INTO [ABCD].[dbo].[switchover] ([when]) VALUES (<when, ntext,>) I need to insert a datetime from the system and a text “Switchover” When I tried with INSERT INTO [ABCD].[dbo].[switchover] ([when]) VALUES (switchover, getdate(),) There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
If I want to get this to be inserted how I should write the statement.
Please help me
Thank You All In Advance KRS39 |
|
|
stepson
Yak Posting Veteran
Romania
85 Posts |
Posted - 11/29/2012 : 04:13:18
|
insert into [ABCD].[dbo].[switchover](columnName1,columName2) values('switchover', getdate())
Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut sabinWeb |
 |
|
|
stepson
Yak Posting Veteran
Romania
85 Posts |
Posted - 11/29/2012 : 04:14:48
|
columnName1= put your column name
the same is for columnName2
Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut sabinWeb |
 |
|
|
ksr39
Posting Yak Master
India
171 Posts |
Posted - 11/29/2012 : 06:04:32
|
but i have only one column defined in the table.. INSERT INTO [Test].[dbo].[switchover] ([when]) VALUES (<when, ntext,>)
if i select the query select * from switchover i get this result (switchover 2012-11-16 21:04:59.977) so i have to insert a single value.
Thank You All In Advance KRS39 |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22460 Posts |
Posted - 11/29/2012 : 06:12:25
|
If you want to select datetime value along with data, use
select ]when],getdate() as date_col from [Test].[dbo].[switchover]
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8513 Posts |
Posted - 11/29/2012 : 06:26:25
|
insert table(col1) select 'switchover' + ' ' + convert(varchar(30),getdate(),121)
Too old to Rock'n'Roll too young to die. |
 |
|
| |
Topic  |
|