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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 convert and cast error

Author  Topic 

thanksfor help
Posting Yak Master

106 Posts

Posted - 2005-06-20 : 14:35:53
Hi,

I need help in following query. I am try to give precision and scale for decimal value in a dynamic query.

DECLARE @P AS int
DECLARE @S AS int
SET @P = 3
SET @S = 0
exec('

SELECT CONVERT(DECIMAL(' +cast( @P as varchar) + ',' + cast(@S as varchar) + '), RTRIM(LTRIM(''123.3'')))')

I am getting "Incorrect syntax near 'cast'" error.

Any help is appreciated

thanks

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-06-20 : 14:40:50
try building the string first:


DECLARE @P AS int
DECLARE @S AS int

SET @P = 3
SET @S = 0

Declare @sqlStr nvarchar(1000)
Select @sqlStr = '

SELECT CONVERT(DECIMAL(' +cast( @P as varchar) + ',' + cast(@S as varchar) + '), RTRIM(LTRIM(''123.3'')))'

exec(@sqlStr)


Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page
   

- Advertisement -