none
Left function RRS feed

  • Question

  • Hi,

    I need to cut a value before the x in it.

    Example, my data is 12345 x 84354

    I just need what is in front of the x, I tried using the Left function but the problem is that the number of digit in front of the x changes. It can be 23894905 x 2483429 or 142 x 028434 and many other possibilities. Is there a way to use only one side of the x?

    Thanks and best regards

    Thursday, July 25, 2019 1:57 PM

All replies

  • DECLARE @s varchar(50) = '12345 x 84354';
    SELECT LEFT(@s, CHARINDEX('x', @s) - 1);

    A Fan of SSIS, SSRS and SSAS

    Thursday, July 25, 2019 2:09 PM
  • Hi,

    Use this :

    SELECT LEFT('12345 x 84354',CHARINDEX('x','12345 x 84354',0)-1)


    Ousama EL HOR

    [If a post helps to resolve your issue, please click the "Mark as Answer"  of that post or click Answered "Vote as helpful"  button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


     [User Page]     [MSDN Page]     [Blog]     [Linkedin]

    Thursday, July 25, 2019 2:12 PM
  • Hi Samuel,

    Above they both give great solution as SQL query.

    I wonder if you are need some expressions in SSRS report?

    If so, you could try:

    =split("12345 x 84354","x")(0)

    Replace the "12345 x 84354" with your data field,  this will give you the string before "x"

    Best Regards,

    Lukas


    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.

    Friday, July 26, 2019 2:11 AM
  • Hi Samuel,

    You can achieve it using SubString function as well:

    SELECT SUBSTRING('12345 x 84354',1,CHARINDEX('x','12345 x 84354',0)-1)

    Hope it helps...


    Pavan Kokkula

    Friday, July 26, 2019 6:07 AM