Strange result....

  • Hi,first of all, sorry for my English...

    After 8 years in oracle we are moving to MSql and i'm having some issues....

    The first of them:

    I have this pice of code:

    declare

    @a as varchar(25);

    begin

    set @a = 'q246_pantilla_normal';

    select @a;

    SELECT *

    FROM imp.sdicd_section

    WHERE

    object_name=@a;

    SELECT *

    FROM imp.sdicd_section

    WHERE

    object_name='q246_plantilla_normal';

    end;

    The first select returns the value assigned to the variable, all ok.

    The second query returns 0 rows, and the third one returns 2 rows.

    Why the second query not return the same 2 rows than the third?

  • The reason that the second query returns zero data (as compared to third query) is because you have assigned the variable the value 'q246_pantilla_normal' (used in first and second queries) while the third query is looking for 'q246_plantilla_normal'.

    note the extra 'l'

    'q246_pantilla_normal' -- parameter

    'q246_plantilla_normal' -- hard coded string

    I remember making a similar mistake and pouring over my SQL for hours to try and track down the issue, only to find a simple misspelling. 😀

  • ohhh, sorry....

    too much querys for me today....

    Thanks!!

  • adiaz 16837 (12/12/2014)


    ohhh, sorry....

    too much querys for me today....

    Thanks!!

    Or not enough coffee 😀

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices

  • :-D:-D:-D:-D:-D

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

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