Copy result to Excel missing "0" at front

  • I ran the query below and then copy result to Excel but missing "0" at front for [MemberID] (varchar)

    Select MemberID from Member

    Data in SQL table is like below:

    MemberID

    05368

    13698

    Data in Excel is like below:

    5368

    13698

    How to fix it?

  • Before copying, format the column as Text.

    Alternatively, you can use

    SELECT '''' + MemberID AS MemberID FROM Member

    to add an apostrophe before the string so Excel will treat it as text without changing the value.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • How to format?

    Result is displaying in SQL management studio.

  • Format the column in Excel before it gets the data.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Usualy I just copy from result window in SQL and then paste into first cell of Excel.

    I'll try your way.

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

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