SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert datetime
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ksr39
Posting Yak Master

India
179 Posts

Posted - 11/29/2012 :  04:06:43  Show Profile  Reply with Quote
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
Constraint Violating Yak Guru

Romania
420 Posts

Posted - 11/29/2012 :  04:13:18  Show Profile  Reply with Quote
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
Constraint Violating Yak Guru

Romania
420 Posts

Posted - 11/29/2012 :  04:14:48  Show Profile  Reply with Quote
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

India
179 Posts

Posted - 11/29/2012 :  06:04:32  Show Profile  Reply with Quote
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

India
22755 Posts

Posted - 11/29/2012 :  06:12:25  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8764 Posts

Posted - 11/29/2012 :  06:26:25  Show Profile  Visit webfred's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000