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.
Author |
Topic |
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2014-11-01 : 05:36:38
|
Hi All,I got error:Conversion failed when converting the nvarchar value to data type int.declare @deci intdeclare @UserName nvarchar(200)declare @decimal nvarchar(2)set @decimal='0D'set @UserName='Micnie'select @deci=case when @decimal='0D' then 0 else 8 endSET @sSQL=' SELECT 'SET @sSQL=@sSQL+' Price=Round((Price/Rate),Convert(Int,'+@deci+')) 'SET @sSQL=@sSQL+' FROM TBL_'+@UserNameEXEC sp_executesql @sSQL Please help.Thank you.Regards,Micheale |
|
mole999
Starting Member
49 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-11-01 : 09:40:07
|
[code]declare @deci intdeclare @UserName nvarchar(200)declare @decimal nvarchar(2)set @decimal='0D'set @UserName='Micnie'select @deci=case when @decimal='0D' then 0 else 8 endSET @sSQL=' SELECT 'SET @sSQL=@sSQL+' Price=Round(Price / Rate, ' + CONVERT(VARCHAR(12), @deci) + ') 'SET @sSQL=@sSQL+' FROM TBL_'+@UserNameEXEC sp_executesql @sSQL [/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|