• me a little bit confused too, what's the difference between this Question, and the one 2 days ago?

    TODAY

    CASTing

    Second question of day: what is the len of @C?

    declare @C varchar(800)

    set @C = N'hello' + replicate('-',800)

    print len(@c)

    print @C

    Sorry - you were wrong

    Correct answer: 800

    Explanation:

    The CAST to nvarchar(800) has a maximum 4000 character len. The CAST then to varchar(800) fits in that space, so the len is 800

    2 days ago

    CASTing

    First question of day: what is the len of @C?

    declare @C varchar(8000)

    set @C = N'hello' + replicate('-',8000)

    print len(@c)

    print @C

    You got it right!

    Correct answer: 4000

    Explanation:

    The CAST to NVARCHAR(4000) means that the maximum len is 4000, then the cast to varchar(8000) allows more characters, but the string is already truncated.

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005