x

Msg 241, Level 16, State 1, Line 1 Conversion failed when converting datetime from character string.

hi guys

i'm here first time any advice would be appreciated.

                    
insert into ##temp                     
values(convert(varchar,'select StartDate from JFTest11.dbo.FScalar',112),                    
       null,null,null);                    

my question is this: i have one main table ,there is one startdate colom which is datetime type. i make one temp table i want to insert all start date value in temp table using above command. there is 4 lakhs record in main table. there is need some change in my query to get all data in temp table pls.

when i'm running this command i got error message all time

Msg 241, Level 16, State 1, Line 1 Conversion failed when converting datetime from character string.

pls help me i,m helpless situation .it's very imp for my project. pls mail me on this id vikassharma_47@hotmail.com

thanks
vikas

more ▼

asked Oct 30, 2009 at 08:11 AM in Default

vikas intel gravatar image

vikas intel
11 2 2 2

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

It should be

insert into ##temp
select convert(varchar(8),StartDate,112),null,null,null from JFTest11.dbo.FScalar
more ▼

answered Oct 30, 2009 at 09:43 AM

Madhivanan gravatar image

Madhivanan
1.1k 1 3 6

(comments are locked)
10|1200 characters needed characters left

Or possibly this:

            
insert into ##temp             
SELECT convert(varchar,(select StartDate from JFTest11.dbo.FScalar),112),            
       null,null,null            

This will give an error IF the nested select returns more than one row (which may be what you want :) )

more ▼

answered Nov 13, 2009 at 12:02 PM

Kristen gravatar image

Kristen ♦
2.2k 6 7 10

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1945
x103

asked: Oct 30, 2009 at 08:11 AM

Seen: 4677 times

Last Updated: Nov 13, 2009 at 12:03 PM