Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert string to datetime
Message
 
To
24/11/2006 10:43:58
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01172273
Message ID:
01172276
Views:
11
>Hello.
>I have a question.
>
>If I have something like this:
>
>declare @cmd varchar (4000)
>declare @server varchar(20),@base varchar (20)
>declare @monto varchar(20)
>declare @num varchar(20)
>declare @date datetime
>set @server='CPSI-SERVER'
>set @base='reaseguro'
>set @monto=123.456
>set @num=22
>set @date='20061212'--(select getdate())--'10/12/2006'
>set @cmd= 'insert into ['+@server+'].['+@base+'].[dbo].[prubtrig]
>([monto],[numero],[fecha])values('+@monto+','+@num+','+@date+')'
>exec (@cmd)
>
>where ([monto],[numero],[fecha]) are (decimal,int,datetime) and I need put this parameters whit variables.
>But SQL say sintaxis error to convert a string in a datetime.
>I can put [monto] and [numero] like varchar but [fecha] I can't.
>How can I put the date?
set @cmd= 'insert into ['+@server+'].['+@base+'].[dbo].[prubtrig]
           ([monto],[numero],[fecha])values('+@monto+','+@num+','''+CONVERT(varchar(8),@date,112)+''')'
exec (@cmd)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform