How to cast this as nvarchar!

  • '0' as Account

    The source column is varchar(1) but i need this as nvarchar(1).. How can I cast this as NVARCHAR...

    Tnx GuruSQL

  • CAST(<source column>) as NVarchar(1))

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (6/5/2015)


    CAST(<source column>) as NVarchar(1))

    CAST(('0' as franchiseevendaccount) as NVARCHAR(1))

    ---

    Incorrect syntax near the keyword 'as'.

  • CAST('0' as NVARCHAR(20))as Account,

    I fix it

  • GG_BI_GG (6/5/2015)


    GilaMonster (6/5/2015)


    CAST(<source column>) as NVarchar(1))

    CAST(('0' as franchiseevendaccount) as NVARCHAR(1))

    ---

    Incorrect syntax near the keyword 'as'.

    Well, yes that's going to give an error. Aliases go after the column definition, not in the middle of a function.

    CAST('0' as NVARCHAR(1)) as Franchiseevendaccount

    Or, you could skip the cast altogether and define it as a unicode string from the start

    N'0' as Franchiseevendaccount

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (6/5/2015)


    GG_BI_GG (6/5/2015)


    GilaMonster (6/5/2015)


    CAST(<source column>) as NVarchar(1))

    CAST(('0' as franchiseevendaccount) as NVARCHAR(1))

    ---

    Incorrect syntax near the keyword 'as'.

    Well, yes that's going to give an error. Aliases go after the column definition, not in the middle of a function.

    CAST('0' as NVARCHAR(1)) as Franchiseevendaccount

    Or, you could skip the cast altogether and define it as a unicode string from the start

    N'0' as Franchiseevendaccount

    Never knowing that N syntax 🙂 tnx a lot.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply