Quantcast
Channel: SQL Server Setup & Upgrade forum
Viewing all articles
Browse latest Browse all 5760

how insert smalldatetime variable into table by sqlCommand?

$
0
0

hi to all,

we want insert a value of smalldatetime variable into a table,but have problme,pls help us.

create table Test2
    (
        name varchar(100),
        b_date smalldatetime
    )

Declare @name varchar(100)='SAM2'
Declare @date smalldatetime='2013-08-24 00:00:00'
Declare @SQL_command varchar(max)

set @SQL_command=
    'insert into Test2
        (
            name,
            b_date
        )
    VALUES
        (
            '+CAST(@name as varchar(100))+',
            '+CAST(@date as varchar(25))+'
        )'

Exec(@SQL_command)    
        
select *
from Test2   


Result:

Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '24'.

(1 row(s) affected)


Viewing all articles
Browse latest Browse all 5760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>