locked
SQL Select with condition RRS feed

  • Question

  • Hi,

    in my sql table,  there is a column which have string of text.  For example
    Column0
    2ABF   CD000000000012345000000000001156
    3000000000003452000000000000356

    I would like if the 1st character is 2 then  out put as

    ID

                              Code     

    Num1                   

    Num2

    Num3

    Num4

    1ABF       

    CD

    123.45

    11.56

    if the 1st character is 3 then

    ID

                              Code     

    Num1                   

    Num2

    Num3

    Num4

       

    34.52     

    3.56

    Finally, combine the them for the result

    ID

                              Code     

    Num1                   

    Num2

    Num3

    Num4

        1ABF

    CD

    123.45

    11.56

    34.52     

    3.56

    Please advise is there a way to do this.

    Thanks so much,

    Ddee

    Friday, September 18, 2020 8:59 PM

Answers

  • Hi ddee,
    I am glad you have got your solution. We appreciated you shared us your solution. And we also hope you can mark it as an answer. By marking a post as Answered, you help others find the answer faster.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ddee Tuesday, September 29, 2020 12:56 PM
    Wednesday, September 23, 2020 1:20 AM

All replies

  • Hi ddee,
    What are the rules for dividing your text of column0? 
    According to your example, do you keep two decimal places?
    Such as 12345->123.45, 3452->34.52
    Please explain in detail.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 21, 2020 9:27 AM
  • Thanks Daniel for your assistant. I am all set with this.

    Ddee

    Tuesday, September 22, 2020 6:56 PM
  • Hi ddee,
    I am glad you have got your solution. We appreciated you shared us your solution. And we also hope you can mark it as an answer. By marking a post as Answered, you help others find the answer faster.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ddee Tuesday, September 29, 2020 12:56 PM
    Wednesday, September 23, 2020 1:20 AM
  • Hi Daniel,

    This project is not moving forward so we don't do it anymore.

    Thanks for your assistant.

    Ddee

    Tuesday, September 29, 2020 12:56 PM