We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Error converting data type varchar to numeric.

Last post 05-18-2008 6:14 AM by yogeshkadvekar. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-16-2008 8:32 AM

    Error converting data type varchar to numeric.

    hi

    i m writting following code

    declare @i as numeric(18,0)
    declare @sql as varchar(8000)

    set @i =4

    set @sql ='select top '+@i+' * from dbo.tbl_ls_feed_data'
    exec(@sql)


    i mgetting error 

     to Error converting data type varchar to numeric.

    how to cast @i in this case

     

    Yogesh Kadvekar


    " It is so simple to be happy, but it is so difficult to be simple."
    • Post Points: 10
  • 05-16-2008 9:21 AM In reply to

    • TimL
    • Top 150 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 980

    Re: Error converting data type varchar to numeric.

    Because @sql is varchar, @i must also be varchar when constructing your dynamic sql string.

    The following should resolve your problem



    declare @i as numeric(18,0)
    declare @sql as varchar(8000)

    set @i =4

    set @sql ='select top '+ CAST(@i AS VARCHAR) + ' * from dbo.tbl_ls_feed_data'
    exec(@sql)

    • Post Points: 10
  • 05-18-2008 6:14 AM In reply to

    Re: Error converting data type varchar to numeric.

     thanks lot

    i did it  same way 

    Yogesh Kadvekar


    " It is so simple to be happy, but it is so difficult to be simple."
    • Post Points: 5
Page 1 of 1 (3 items)