Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert string to datetime
Message
 
À
24/11/2006 10:43:58
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01172273
Message ID:
01172276
Vues:
12
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform