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
 General SQL Server Forums
 New to SQL Server Programming
 Conversion failed when converting datetime from ch

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-07-07 : 17:53:49
simplified version of an issue im having in a sp

@string varchar(100),
@date datetime,
@TableName varchar(30),
@Database varchar(30)


DECLARE @sql varchar(8000)

SET @SQL = 'Insert into ' + @Database + @TableName + '(string, date)
Values(' + @String + ',' + @date + ')'

EXEC (@SQL)

Im trying to pass in a date and keep getting datetime from char conversion errors. i can cast everything as a varchar.

is there a better way to get around this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-07 : 18:50:11
Cast/Convert is required.

The better way is to not design a system like that. Why do you have tables like that?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -