Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ksr39
Posting Yak Master
193 Posts |
Posted - 2012-11-29 : 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 meThank You All In AdvanceKRS39 |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2012-11-29 : 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 mutsabinWeb |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2012-11-29 : 04:14:48
|
columnName1= put your column name the same is for columnName2Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
ksr39
Posting Yak Master
193 Posts |
Posted - 2012-11-29 : 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 switchoveri get this result(switchover 2012-11-16 21:04:59.977)so i have to insert a single value.Thank You All In AdvanceKRS39 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-11-29 : 06:12:25
|
If you want to select datetime value along with data, useselect ]when],getdate() as date_col from [Test].[dbo].[switchover]MadhivananFailing to plan is Planning to fail |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-11-29 : 06:26:25
|
insert table(col1)select 'switchover' + ' ' + convert(varchar(30),getdate(),121) Too old to Rock'n'Roll too young to die. |
|
|
|
|
|
|
|