Compare String

  • Hello everyone

    I need to compare to string in sql

    requirement is

    Select Reson_id from reason_data where reason='ryete / werewr ddsad '

    is there any way without string function? bcz string function take more exaction time

  • meerack11 (6/19/2015)


    Hello everyone

    I need to compare to string in sql

    requirement is

    Select Reson_id from reason_data where reason='ryete / werewr ddsad '

    is there any way without string function? bcz string function take more exaction time

    Please explain what you mean by: "without string function".



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I'm afraid you will need to be more specific. What 'String' are you trying to compare? Do you need help modifying your statement?

    Select Reson_id from reason_data where reason='ryete / werewr ddsad '

    Please provide a sample of data and what your expected results are.

    Here is a good place to start: http://qa.sqlservercentral.com/articles/Best+Practices/61537/

    Thanks,


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • I mean SUBSTRING or other function

  • I am comparing string like 'djfs / esfsdf '

  • the string contain space and slash

  • What's the problem with space and slash? Those are just characters as any other in a string.

    is there any way without string function? bcz string function take more exaction time

    Do some microseconds really matter? That's the extra execution time to apply a function on a string.

    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
  • AI had use = and like but it doent work

  • meerack11 (6/19/2015)


    AI had use = and like but it doent work

    Doesn't work? What do you mean? An error? Incorrect results?

    What was the input? What does the data look like? What are the expected results? Share more information, share details, help us help you.

    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
  • Here is the problem, we can't see what you see. We don't have access to your systems, we don't know what the data looks like, and we don't fully understand what it is you are trying to accomplish. You need to help us help you. Step 1, read the first article you will find linked in my signature block. Step 2, follow the steps in that article to post the information we need to help you.

  • select * from GLCode_DATA where GLCode ='602-434345_Planning - Expedited Air'

    in table GL code='602-434345_Planning - Expedited Air' is variable but result show me nothing

  • select * from GL_CODE_DATA where Gl_code='602-434345_Planning - Expedited Air'

    I have Gl_code='602-434345_Planning - Expedited Air' in table but result show me nothing

  • select * from Gl_code_data where Gl_code='602-43335_Planning - Expedited Air'

    I have Gl_code='602-434345_Planning - Expedited Air' this record in table but result show me nothing

  • You might not have that value in your table or maybe you're not really comparing to that value

    The following code might give you ideas to look for.

    CREATE TABLE #GLCode_DATA

    (

    GLCode varchar(100)

    )

    INSERT INTO #GLCode_DATA

    VALUES('602-434345_Planning - Expedited Air'), ('602-434345_Planning' + CHAR(10) + '- Expedited Air')

    select * from #GLCode_DATA --2 rows

    select * from #GLCode_DATA

    where GLCode ='602-434345_Planning - Expedited Air' --1 row

    DECLARE @GlCode varchar --Incorrect Declaration

    SET @GlCode = '602-434345_Planning - Expedited Air'

    select * from #GLCode_DATA where GLCode = @GlCode --0 rows

    SELECT @GlCode --The string is trunctated

    GO

    DECLARE @GlCode varchar(100)

    SET @GlCode = '602-434345_Planning - Expedited Air'

    select * from #GLCode_DATA where GLCode = @GlCode --1 row

    GO

    DROP TABLE #GLCode_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
  • meerack11 (6/19/2015)


    select * from Gl_code_data where Gl_code='602-43335_Planning - Expedited Air'

    I have Gl_code='602-434345_Planning - Expedited Air' this record in table but result show me nothing

    This one should not show you anything because the 2 strings are different.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 15 posts - 1 through 15 (of 26 total)

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