none
Convert int to varchar(max)

Answers

  • Hi,

    Try this

    DECLARE @ID INT

    SET @ID = 1

    SELECT CAST(@ID AS VARCHAR) 

    OR

    SELECT CONVERT(VARCHAR, @ID)
    Rajesh Jonnalagadda http://www.ggktech.com
    • Marked as answer by Banafsheh Monday, February 08, 2010 11:33 AM
    Monday, February 08, 2010 10:19 AM

All replies

  • Hi,

    Try this

    DECLARE @ID INT

    SET @ID = 1

    SELECT CAST(@ID AS VARCHAR) 

    OR

    SELECT CONVERT(VARCHAR, @ID)
    Rajesh Jonnalagadda http://www.ggktech.com
    • Marked as answer by Banafsheh Monday, February 08, 2010 11:33 AM
    Monday, February 08, 2010 10:19 AM
  • Convert(nvarchar(max),UnitNumbers)

    and for mine UnitNumber is int .

    it's true :)
    Monday, February 08, 2010 10:26 AM
  • Hi There,

    Why you want to store Int Data Type to Varchar(Max), You can store Int Values uplto max 10 characters so i would like to suggest you to store into varchar(10) not in varchar(max). You can use following queries.

    Declare @MyVar Int
    Select @MyVar = 20000
    Select Cast(@MyVar as Varchar(max) --I would not suggest but as per your question.
    Select Cast(@MyVar as Varchar(10)) -- Length Should be enough to store int values.


    See following suggestion from Mircrosoft.

  • Use char when the sizes of the column data entries are consistent.
  • Use varchar when the sizes of the column data entries vary considerably.
  • Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.
  • Also visit http://msdn.microsoft.com/en-us/library/ms176089.aspx for more informations.

    Regards,

    Balwant.


    Failure in Life is failure to try...
Monday, February 08, 2010 10:30 AM