Unable to pass concatenated string in @vSQL for multislect

(4 posts) (2 voices)

Tags:

No tags yet.

  1. Deepak, Member

    Hi,

    I am trying to adapt a similar approach what has been shown in the Multi-select Example in Demo The difference what i have implemented is i am concatenating 2 ids with a '-' separator.
    parameter query,

    select concat(cast(tm.childid as char),'_',cast(tm.masterid as char)),tmm1.TAXVALDESC,tmm.TAXVALDESC
    from sipo_db.tm_m_ibm_codevaluemaps tm
    join sipo_db.tm_m_ibm_taxdtls tmm on tmm.id=tm.masterid and tmm.type_id=1
    join sipo_db.tm_m_ibm_taxdtls tmm1 on tmm1.id=tm.childid and tmm1.type_id=2
    order by tmm.TAXVALDESC,tmm1.TAXVALDESC;

    Result:


    id Minor_brand Major_brand
    6225_5970 ACI - General ACI (AJ)
    6226_5971 Aerospace and Defense - General Aerospace and Defense (AE)
    6227_5971 Integrated Service Management Aerospace and Defense (AE)

    Now that i am using multiselect i have both temporary table and inparameter data type set as text.

    I am using


    set @vSQL = concat('INSERT INTO ','data_tmp', ' VALUES(\'', REPLACE(inMajorBrand , ',', '\'),(\''), '\')');
    prepare stmt from @vSQL;
    execute stmt;
    deallocate prepare stmt;

    The 'inMajorBrand '(concatenated value) doesnt get inserted to temp table in this approach.
    However if the id is just an integer like '6225' or '6226' there is no problem. I have also tried type casting it as char but in vain.

  2. myDBR Team, Key Master

    You could show the @vSQL variable content prior to the prepared statement. It should contain valid SQL.

    --
    myDBR Team

  3. Deepak, Member

    @vSQL variable content is nothing but the 'id'(concatenated integers) which is passed as the 'inMajorBrand' parameter.

  4. myDBR Team, Key Master

    As you are using prepared statements, the statement in question (stored in @vSQL) should be a valid SQL statement. Check your code what is wrong.

    You can just place "select @vSQL" before the prepared statements to see what is the value for @vSQL.

    --
    myDBR Team


Reply

You must log in to post.