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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert datetime

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 me



Thank You All In Advance
KRS39

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 mut
sabinWeb
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2012-11-29 : 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
Go to Top of Page

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 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
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-29 : 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
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -