locked
Difference between CAST(CLOUMN AS VARCHAR) and CAST(COLUMN AS VARCHAR(100)),CAST(COLUMN AS VARCHAR(MAX)) RRS feed

  • Question

  • Hi All,

    I would like to know the difference between CAST(CLOUMN AS VARCHAR) and CAST(COLUMN AS VARCHAR(100)),CAST(COLUMN AS VARCHAR(MAX)).

    I noticed that Length of CAST(CLOUMN AS VARCHAR) is only 30 but did not understand why?

    Where as DECLARE @V VARCHAR SET @V='All Right'  SELECT Len(@V) is only 1, why this?

    Sample Query:

    DECLARE @V VARCHAR,
            @V1 VARCHAR(100),
    @V2 VARCHAR(MAX)

    SET @V='Sydney is in lockdown as a Jihadi flag flies inside the window of a busy cafe in Sydney Martin Place where a gunman are holding up to 50 people hostage'
    SET @V1='Sydney is in lockdown as a Jihadi flag flies inside the window of a busy cafe in Sydney Martin Place where a gunman are holding up to 50 people hostage' 
    SET @V2='Sydney is in lockdown as a Jihadi flag flies inside the window of a busy cafe in Sydney Martin Place where a gunman are holding up to 50 people hostage'

    SELECT LEN(@V) L_V,LEN(@V1) L_V1,LEN(@V2) L_V2,@V V,@V1 V1,@V2 V2,LEN(CAST(@V1 AS VARCHAR)) CAST_L_V1, CAST(@V1 AS VARCHAR) CAST_V1



    Thanks Shiven:) If Answer is Helpful, Please Vote


    Monday, December 15, 2014 2:26 AM

Answers

All replies