SQL Task Expression: SQL Command using variable tables

Hello,
I've got a question I hope someone could help me out with. I'm working on a SSIS project that basically synchronises logins of a Source and Destination server that are part of an AlwaysOn Cluster.
The idea is as followed: On the source server there are variable tables created named Logins_<SourceServerName>_To_<DestinationServerName> for example. This one is filled with all the login information from that server, then on the Destination
server the same table is created and the data is transfered. The Source and Destination server names are project variables.
Once all data is copied I use a set of code from the dba_CopyLogins script I got from SQLSoldier (http://www.sqlsoldier.com/wp/sqlserver/transferring-logins-to-a-database-mirror) to create the missing logins on the Destination server.
What I've found is that I can't use expressions to handle the code, at least I haven't found a way yet, expression evaluation will give an error on (for example) the following code:
Begin
Set @SQL = 'Create Login ' + quotename(@LoginName)
If @Type In ('U', 'G')
Begin
Set @SQL = @SQL + ' From Windows;'
End
Else
Begin
Set @PasswordHashString = '0x' +
Cast('' As XML).value('xs:hexBinary(sql:variable("@PasswordHash"))', 'nvarchar(300)');
Set @SQL = @SQL + ' With Password = ' + @PasswordHashString + ' HASHED, ';
Set @SIDString = '0x' +
Cast('' As XML).value('xs:hexBinary(sql:variable("@SID"))', 'nvarchar(100)');
Set @SQL = @SQL + 'SID = ' + @SIDString + ';';
End
I've tried various things to get this to work as an expression, however I seem to continue to get the error:
The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.
So the next thing I tried was just using the script as Direct input with Parameter Mapping on the tables but I've got the error:
Must declare the table variable "@P1".
All the way up to @P12. Since we're talking about 12 variables that are in the script in total. But they are table variables and apparently Parameter mapping is not possible on table variables or am I wrong here? Pieces of code for example are:
Set @MaxID = (Select Max(LoginID) From ?)
Set @CurrID = (Select Min(LoginID) From ?)
I hope there's someone who could help me out or at least can give me a direction to look into.
Yes we could use the script provided, but we don't want to work with LinkedServers, besides I'd have to make local jobs on the servers instead of controlling it all from 1 centralised server.
Thank for looking at the topic and I hope you have a clue about what to do...
Regards,
Danny

The code you posted is a t-sql code. If you want to store it inside ssis variable syntax is different. As per what you say what might be best would be to warp above code inside a procedure and then call it from SSIS execute sql task after passing values
through SSIS variable
also for 
Set @MaxID = (Select Max(LoginID) From ?)
etc
create variable in SSIS, set EvaluateAsExpression true and set expression as
"Select Max(LoginID) AS MaxID From " + @[User::TableName]
Where TableName is SSIS variable through which you pass the table name. Then use above statement inside execute sql task and set resultset option as single row and map resultset to SSIS variable (say @[User::MaxID]) to get return value 
similarly for other statements
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How to use lengthy query in a "SQL Command from Variable"

    My oracle SQL Query length is more than 14000 characters, so how can i use this for "SQL command from variable".
    Sarvan

    Either create a view or a table valued UDF. Using stored procedure in OLEDB source has some gotchas it will not pick up metadata information by default due to late binding.
    http://consultingblogs.emc.com/jamiethomson/archive/2006/12/20/SSIS_3A00_-Using-stored-procedures-inside-an-OLE-DB-Source-component.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How can I search multiple columns in a SQL command of Union tables

    Hi:
    We have a database with tables that are nearly identical that we use for production and production history.
    I have created an SQL command in Crystal 2008 to joins several of the tables and then added a "UNION" to connect the History and Prod tables.
    I need to search multiple (3 total) columns for 5 different data types, to return the records being investigated. I tried this using an "OR" statement in the where clause and have had inconsistant results.
    The first two or statement function perfectly the third works as long as the value being passed is numeric and the last two fail consistantly with invalid column name errors. It appears that crystal is getting confused and passing the wrong data type especially if I do a new search using a different option for the "?SearchParam"
    Can some one offer some insite on how I can search these fields to return the record data needed
    -- {?SearchParam} is the search parameter passed by Crystal that is a number 1 thru 5
    -- {?Search_Val} is a parameter that is passed by Crystal that is a string of what to search for 1 = Numeric CMP ord #("TBSLI21"."LI21_OR_NO"), 2 = Numeric CI ord # ( "TBSLI33"."LI33_CI_OR_NO"),
    --   3 =String  Ext Sys ord string ("TBSLI33"."LI33_EXT_SYS_SL_OR_NO"), 4 = String CMP Grp string ("TBSLI21"."LI21_OP_GRP_NO"), 5 = composit string PP ord string ("TBSOP13"."OP13_CLR_DAY" & "TBSOP13"."OP13_PP_GRP_SEQ_NO" & "TBSOP13"."OP13_CELL_ID")
    SELECT "TBSLI21"."LI21_OR_NO",
    "TBSLI21"."LI21_SH_DT_SCDL",
    "TBSLI21"."LI21_TS_EN_ORIG",
    "TBSLI21"."LI21_TS_SHIP",
    "TBSLI21"."LI21_SYS_ORD_CD",
    "TBSLI21"."LI21_SHIP_ID",
    "TBSLI21"."LI21_WRKST_ID",
    "TBSLI21"."LI21_LI_NO",
    "TBSLI33"."LI33_CI_OR_NO",
    "TBSLI33"."LI33_EXT_SYS_SL_OR_NO",
    "TBSLI21"."LI21_OP_GRP_NO",
    "TBSLI21"."LI21_LI_STAT",
    "TBSOP13"."OP13_OP_GRP_STAT",
    "TBSLI31"."LI31_LI_EV_DTL_TX",
    "TBSLI31"."LI31_DT_EN",
    "TBSLI31"."LI31_TM_EN",
    "TBSLI31"."LI31_LI_EV",
    "TBSLI21"."LI21_OP_WSH_FLNM",
    "TBSLI21"."LI21_PR_ITF_CD",
    "TBSLI21"."MFG_PLANT_CD",
    "MFG_PLANT_LI"."MFG_PLANT_CD" as PrefPlant,
    "TBSOP13"."OP13_OP_GRP_DSP_CD",
    "TBSLI21"."LI21_LI_DSP_CD",
    "TBSOP13"."OP13_CLR_DAY",
    "TBSOP13"."OP13_PP_GRP_SEQ_NO",
    "TBSOP13"."OP13_CELL_ID",
    "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG",
    "TBSLI21"."LI21_OP_GRP_PS_NO1",
    "TBSLI21"."LI21_POMS_MERGE_NO",
    "TBSLI31"."LI31_OP_ID",
    "TBSLI21"."LI21_LI_POR_FG",
    "TBSLI21"."LI21_BIN_ID",
    "TBSLI21"."LI21_TS_MRSHL",
    "TBSLI33"."LI33_CI_LI_NO",
    "TBSLI33"."LI33_SH_ADDR_1",
    "TBSLI33"."LI33_SH_ADDR_2",
    "TBSLI33"."LI33_SH_ADDR_3",
    "TBSLI33"."LI33_SH_ADDR_4",
    "TBSLI33"."LI33_SH_CITY_NM",
    "TBSLI33"."LI33_SH_ST_NM",
    "TBSLI33"."LI33_SH_ZIP_CD",
    "TBSLI33"."LI33_CU_NM",
    "TBSLI33"."LI33_CU_BUS_NM"
    FROM   ((("CMPREPORTING"."dbo"."TBSLI33" "TBSLI33" FULL OUTER JOIN "CMPREPORTING"."dbo"."TBSLI21" "TBSLI21" ON ("TBSLI33"."LI33_BS_OR_NO"="TBSLI21"."LI21_OR_NO") AND ("TBSLI33"."LI33_BS_LI_NO"="TBSLI21"."LI21_LI_NO")) LEFT OUTER JOIN "CMPREPORTING"."dbo"."TBSOP13" "TBSOP13" ON "TBSLI21"."LI21_OP_GRP_NO"="TBSOP13"."OP13_OP_GRP_NO") LEFT OUTER JOIN "CMPREPORTING"."dbo"."TBSLI31" "TBSLI31" ON ("TBSLI21"."LI21_OR_NO"="TBSLI31"."LI31_OR_NO") AND ("TBSLI21"."LI21_LI_NO"="TBSLI31"."LI31_LI_NO")) LEFT OUTER JOIN "CMPREPORTING"."dbo"."MFG_PLANT_LI" "MFG_PLANT_LI" ON ("TBSLI21"."LI21_OR_NO"="MFG_PLANT_LI"."OR_NO") AND ("TBSLI21"."LI21_LI_NO"="MFG_PLANT_LI"."LI_NO")
    WHERE   {?aSearchParam} = 1 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI21"."LI21_OR_NO"=Cast( {?Search_Val} as Int)
    or {?aSearchParam} = 2 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI33"."LI33_CI_OR_NO"=Cast( {?Search_Val} as numeric(12,0))
    or {?aSearchParam} = 3 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(20),"TBSLI33"."LI33_EXT_SYS_SL_OR_NO")= Convert( VarChar(20), {?Search_Val})
    or {?aSearchParam} = 4 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8),"TBSLI21"."LI21_OP_GRP_NO") = Convert( VarChar(8), {?GroupNo})
    or {?aSearchParam} = 5 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8), ("TBSOP13"."OP13_CLR_DAY" & "TBSOP13"."OP13_PP_GRP_SEQ_NO" & "TBSOP13"."OP13_CELL_ID")) = Convert( VarChar(8), {?GroupNo})
    Union
    SELECT "TBSLI21_HIST"."LI21_OR_NO",
    "TBSLI21_HIST"."LI21_SH_DT_SCDL",
    "TBSLI21_HIST"."LI21_TS_EN_ORIG",
    "TBSLI21_HIST"."LI21_TS_SHIP",
    "TBSLI21_HIST"."LI21_SYS_ORD_CD",
    "TBSLI21_HIST"."LI21_SHIP_ID",
    "TBSLI21_HIST"."LI21_WRKST_ID",
    "TBSLI21_HIST"."LI21_LI_NO",
    "TBSLI33_HIST"."LI33_CI_OR_NO",
    "TBSLI33_HIST"."LI33_EXT_SYS_SL_OR_NO",
    "TBSLI21_HIST"."LI21_OP_GRP_NO",
    "TBSLI21_HIST"."LI21_LI_STAT",
    "TBSOP13_HIST"."OP13_OP_GRP_STAT",
    "TBSLI31_HIST"."LI31_LI_EV_DTL_TX",
    "TBSLI31_HIST"."LI31_DT_EN",
    "TBSLI31_HIST"."LI31_TM_EN",
    "TBSLI31_HIST"."LI31_LI_EV",
    "TBSLI21_HIST"."LI21_OP_WSH_FLNM",
    "TBSLI21_HIST"."LI21_PR_ITF_CD",
    "TBSLI21_HIST"."MFG_PLANT_CD",
    "MFG_PLANT_LI_HIST"."MFG_PLANT_CD",
    "TBSOP13_HIST"."OP13_OP_GRP_DSP_CD",
    "TBSLI21_HIST"."LI21_LI_DSP_CD",
    "TBSOP13_HIST"."OP13_CLR_DAY",
    "TBSOP13_HIST"."OP13_PP_GRP_SEQ_NO",
    "TBSOP13_HIST"."OP13_CELL_ID",
    "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG",
    "TBSLI21_HIST"."LI21_OP_GRP_PS_NO1",
    "TBSLI21_HIST"."LI21_POMS_MERGE_NO",
    "TBSLI31_HIST"."LI31_OP_ID",
    "TBSLI21_HIST"."LI21_LI_POR_FG",
    "TBSLI21_HIST"."LI21_BIN_ID",
    "TBSLI21_HIST"."LI21_TS_MRSHL",
    "TBSLI33_HIST"."LI33_CI_LI_NO",
    "TBSLI33_HIST"."LI33_SH_ADDR_1",
    "TBSLI33_HIST"."LI33_SH_ADDR_2",
    "TBSLI33_HIST"."LI33_SH_ADDR_3",
    "TBSLI33_HIST"."LI33_SH_ADDR_4",
    "TBSLI33_HIST"."LI33_SH_CITY_NM",
    "TBSLI33_HIST"."LI33_SH_ST_NM",
    "TBSLI33_HIST"."LI33_SH_ZIP_CD",
    "TBSLI33_HIST"."LI33_CU_NM",
    "TBSLI33_HIST"."LI33_CU_BUS_NM"
    FROM   ((("CMPREPORTING"."dbo"."TBSLI33_HIST" "TBSLI33_HIST" FULL OUTER JOIN "CMPREPORTING"."dbo"."TBSLI21_HIST" "TBSLI21_HIST" ON ("TBSLI33_HIST"."LI33_BS_OR_NO"="TBSLI21_HIST"."LI21_OR_NO") AND ("TBSLI33_HIST"."LI33_BS_LI_NO"="TBSLI21_HIST"."LI21_LI_NO")) LEFT OUTER JOIN "CMPREPORTING"."dbo"."TBSOP13_HIST" "TBSOP13_HIST" ON "TBSLI21_HIST"."LI21_OP_GRP_NO"="TBSOP13_HIST"."OP13_OP_GRP_NO") LEFT OUTER JOIN "CMPREPORTING"."dbo"."TBSLI31_HIST" "TBSLI31_HIST" ON ("TBSLI21_HIST"."LI21_OR_NO"="TBSLI31_HIST"."LI31_OR_NO") AND ("TBSLI21_HIST"."LI21_LI_NO"="TBSLI31_HIST"."LI31_LI_NO")) LEFT OUTER JOIN "CMPREPORTING"."dbo"."MFG_PLANT_LI_HIST" "MFG_PLANT_LI_HIST" ON ("TBSLI21_HIST"."LI21_OR_NO"="MFG_PLANT_LI_HIST"."OR_NO") AND ("TBSLI21_HIST"."LI21_LI_NO"="MFG_PLANT_LI_HIST"."LI_NO")
    WHERE  {?aSearchParam} = 1 and "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI21_HIST"."LI21_OR_NO"= Cast( {?Search_Val} as Int)
    or {?aSearchParam} = 2 and  "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI33_HIST"."LI33_CI_OR_NO"= Cast( {?Search_Val} as numeric(12,0))
    or {?aSearchParam} = 3 and  "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(20), "TBSLI33_HIST"."LI33_EXT_SYS_SL_OR_NO")= Convert( VarChar(20),{?Search_Val})
    or  {?aSearchParam} = 4 and "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8),"TBSLI21_HIST"."LI21_OP_GRP_NO")= Convert( VarChar(8), {?GroupNo} )
    or {?aSearchParam} = 5 and  "MFG_PLANT_LI_HIST"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8), ("TBSOP13_HIST"."OP13_CLR_DAY" & "TBSOP13_HIST"."OP13_PP_GRP_SEQ_NO" & "TBSOP13_HIST"."OP13_CELL_ID")) = Convert( VarChar(8), {?GroupNo})

    This is actually a fairly easy fix - because of the way the "OR" works in SQL, you need to surround each "set" of statements in the or with parentheses.  So, it would look something like this:
    Where
    ({?aSearchParam} = 1 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI21"."LI21_OR_NO"=Cast( {?Search_Val} as Int))
    or
    ({?aSearchParam} = 2 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND "TBSLI33"."LI33_CI_OR_NO"=Cast( {?Search_Val} as numeric(12,0)))
    or
    ({?aSearchParam} = 3 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(20),"TBSLI33"."LI33_EXT_SYS_SL_OR_NO")= Convert( VarChar(20), {?Search_Val}))
    or
    ({?aSearchParam} = 4 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8),"TBSLI21"."LI21_OP_GRP_NO") = Convert( VarChar(8), {?GroupNo}))
    or
    ({?aSearchParam} = 5 and "MFG_PLANT_LI"."PRFR_MFG_PLANT_FLG"='Y' AND Convert( VarChar(8), ("TBSOP13"."OP13_CLR_DAY" & "TBSOP13"."OP13_PP_GRP_SEQ_NO" & "TBSOP13"."OP13_CELL_ID")) = Convert( VarChar(8), {?GroupNo}))
    -Dell

  • Oracle sql commands use

    my question is will it possible to use oracle sql commands in toad and genterate the reprot like I have below.
    my second question is can I embede this oralc sql command in my apps. to have the out put I have below. I tried and got an error message. I am wondering if this is possible
    SQL> -- Multiple COMPUTEs are also allowable.
    SQL>
    SQL> SET echo off
    SQL> BREAK ON city skip1 ON start_date
    SQL> COMPUTE sum max min of salary ON city
    SQL> COMPUTE sum of salary ON start_date
    SQL> SET verify off
    SQL> SELECT id, first_name, salary, city FROM employee ORDER BY city
      2  /
    ID   FIRST_NAME     SALARY CITY
    07   David         7897.78 New York
    06   Linda         4322.78
                       4322.78 minimum
                       7897.78 maximum
                      12220.56 sum
    01   Jason         1234.56 Toronto
                       1234.56 minimum
                       1234.56 maximum
                       1234.56 sum
    05   Robert        2334.78 Vancouver
    08   James         1232.78
    03   James         6544.78
    02   Alison        6661.78
    04   Celia         2344.78
                       1232.78 minimum
                       6661.78 maximum
                       19118.9 sum

    Hi,
    All of theose SQL*Plus features can be duplicated in Oracle SQL. For example, "GROUP BY ... ROLLUP" can give you an minimum, maximum and total for each city.
    You can create a view that looks exactly like the SQL*Plus output (for example, the city column with values like 'New York', NULL, '**********', and 'minimum'), if you really need to. CASE is very useful for things like this, as are some analytic functions. (E.g., ROW_NUMBER can help in telling which is the first row for each city.)
    To make such a view, you may find it convenient to do a UNION of two queries:
    (1) One that produces one row per employee
    (2) One that produces a fixed number of rows (four, to get the results you posted) per city

  • Creating sql query using 3 tables

    There is database (supposed to be relational but it is not) and
    I cannot change the tables and it is very difficult to create SQL query.
    Please, help!
    First table T1
    a1 char 20
    time timestamp
    a2 char 7 (the same as t2.a2 when is trimmed)
    a3 number 5,0
    a4 number 8,4
    a5 number 7,3
    Second table T2
    a2 char 15
    b1 number 1,0
    b2 char 1,0
    b3 char 4
    a3 number 5,0
    Third table T3
    b3 char 4
    c1 char 4
    c2 number 7,3
    c3 number 8,4
    So, I need to create query (is it possible at all!?) from those 3 tables (a1, a2, b1,b2,b3, a4, a5, c2,c3
    where time is within interval (from, to), a3 in interval (1,2,3,4), t2.b3=t3.b3, t1.a2=t2.a2
    group by or sorted by a1, then, a2.
    Any suggestion is welcome!
    Thanks!
    By the way, I will use this query in Crystal Reports.

    As I already mentioned, I received another conditions for the query, and when I create a new one, I
    First table T1
    a1 number 5,0
    a2 char 7 (the same as t2.a2 when is trimmed)
    a3 number 8,4
    a4 number 7,3
    a_time timestamp
    Second table T2
    a2 char 15
    b1 number 1,0
    b2 char 1,0
    b3 char 4
    b4 char 4
    Third table T3
    c1 char 4
    c2 number 7,3
    c3 number 8,4
    b3 char 4
    where if c1='MIN' c2, c3 return min values,
    and if c1='MAX' c2,c3 return max values
    SQL query:
    select t1.a1, t1.a2, t2.b1, t2.b2, t2.b3, t1.a3, t1.a4, t3.c1,
    t3.c2, t3.c3, t2.b4
    from t1, t2, t3
    where (TRIM(t1.a2)=TRIM(t2.a2)
    and t1.a1=19
    and ((to_char(t1.a_time, 'YYYY-MM-DD') >= '2006-03-15')
    and (to_char(t1.a_time, 'YYYY-MM-DD') <= '2006-03-16')))
    and t3.b3=t2.b3)
    order by t1.a_time
    Result set:
    a1, a2, b1, b2, b3, a3, a4, c1('MAX'), c2', c3', b4
    a1, a2, b1, b2, b3, a3, a4, c1('MIN'), c2", c3", b4
    So when I executed SQL query it returns 2 rows for the same a2.
    I want to get 1 row for each a2 together with c3 (c4) min and c3 (c4) max values.
    How to name columns for c2 min and c2 max (the same for c3) in order to retreive 1 row per a2 value, something like this:
    a1, a2, b1, b2, b3, a3, a4, c2min, c2max, c3min, c3max, b4
    Thanks

  • SQL LOADER USING EXTRNAL TABLE

    I have .csv file having around 70k records
    in which fields are delimited by tab and
    enclosed in double quotes but double quotes may be part of data.
    and records are delimited by newline.
    After creating external table when I issue SELECT statment
    select count(*) from proTxt ;
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04020: found record longer than buffer size supported, 524288, in C:\Program Files\Apache Software Foundation\Tomcat
    5.5\webapps\tmTest\upload\product\Data\output09_1.txt
    ORA-06512: at "SYS.ORACLE_LOADER", line 19
    Following is the create table statement:
    CREATE TABLE proTxt (PRO_CODE VARCHAR2(30),
    PRO_DESC VARCHAR2(500),
    PUR_PRICE VARCHAR2(20),
    SALE_PRICE VARCHAR2(20)
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY DAT_DIR
    ACCESS PARAMETERS
    records delimited by NEWLINE SKIP 1
    badfile BAD_DIR:'proTxt%a_%p.bad'
    logfile LOG_DIR:'proTxt%a_%p.log'
    fields terminated by X'9' OPTIONALLY ENCLOSED BY '"' AND '"'
    missing field values are null
    ( PRO_CODE,
    PRO_DESC,
    PUR_PRICE,
    SALE_PRICE
    LOCATION ('output09_1.txt')
    PARALLEL 4
    REJECT LIMIT UNLIMITED;
    record size is not large.
    Log file :
    LOG file opened at 12/05/12 20:25:40
    KUP-04020: found record longer than buffer size supported, 524288, in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\tmTest\upload\product\Data\output09_1.txt
    KUP-04053: record number 2
    data file
    PRO_CODE     PRO_DESC     PUR_PRICE     SALE_PRICE
    "0000336658"     "BEARING"     "Rs.0.00"     "Rs.0.00"
    "0000790028"     "SEAL"     "Rs.76.00"     "Rs.90.00"
    "0000790118"     "SPRING"     "Rs.24.00"     "Rs.28.00"
    "0000792284"     "F.BRK.CAL.W/O PA"     "Rs.2,627.00"     "Rs.3,100.00"
    "0000792285"     "F.BRK.CAL.W/O PA"     "Rs.2,627.00"     "Rs.3,100.00"
    "0005896322"     "PISTON, RING"     "Rs.5,000.00"     "Rs.5,900.00"
    "0005896323"     "PISTONS, RINGS AND P"     "Rs.17,755.00"     "Rs.20,951.00"
    "0005896559"     "PISTON, RINGS AND PI"     "Rs.5,000.00"     "Rs.5,900.00"

    Hi,
    when i used
    records delimited by *'\r'*
    then 4226 record written to table
    but enclosed charcter double quotes["] were also written and
    there is some space between charcters
    " 0 0 0 0 3 3 6 6 5 8 " " B E A R I N G " " R s . 0 . 0 0 " " R s . 0 . 0 0 "
    " 0 0 0 0 8 5 6 7 0 7 " " P L U G " " R s . 0 . 0 0 " " R s . 0 . 0 0 "
    Definitely this is "External Table with Flatfile Moved Across Platforms" issue.
    when I opened .csv file in excel and saved as tab delimited it works fine.
    But I do not know plateform of data file.
    How to know the CHARACTERSET of data file
    Log file
    Field Definitions for table PROTXT
    Record format DELIMITED, delimited by
    Data in file has same endianness as the platform
    Rows with all null fields are accepted
    Fields in Data Source:
    PRO_CODE CHAR (255)
    Terminated by "9"
    Enclosed by """ and """
    Trim whitespace same as SQL Loader
    PRO_DESC CHAR (255)
    Terminated by "9"
    Enclosed by """ and """
    Trim whitespace same as SQL Loader
    PUR_PRICE CHAR (255)
    Terminated by "9"
    Enclosed by """ and """
    Trim whitespace same as SQL Loader
    SALE_PRICE CHAR (255)
    Terminated by "9"
    Enclosed by """ and """
    Trim whitespace same as SQL Loader

  • Cursor using variable table name

    I'm new to Oracle, and am wondering if I can create a cursor that can take a variable name as the table it's selecting from. I am working on an application that is loading data to 1 of 3 tables. The table name is stored as a variable and the loads are done using dymanic sql to constuct the insert statement. At the end, I want to select and process some specific info from the table that's been loaded by cycling thru a cursor on whichever of the 3 tables was populated. I could create 3 cursors, one for each table, test the table_name variable, and then reference the specific cursor that way, but I thought there must be another way to do this. I want to be able to do something like this:
    CURSOR loaded_table is select distinct(process_key) from 'v_tablename' (where v_tablename is either TABLE2, TABLE2 or TABLE3)
    Any suggestions would be greatly appreciated.
    Tks...MCR

    It's possible to use dynamic SQL for something like this. If we're only talking about three tables, though, my hunch is that you'll be much happier defining three different cursors. Dynamic SQL is significantly harder to write, debug, and maintain than static SQL, so you're better off resorting to it only when there are so many tables that static SQL is impractical.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • SQL Query using a Variable in Data Flow Task

    I have a Data Flow task that I created. THe source query is in this file "LPSreason.sql" and is stored in a shared drive such as
    \\servername\scripts\LPSreason.sql
    How can I use this .sql file as a SOURCE in my Data Flow task? I guess I can use SQL Command as Access Mode. But not sure how to do that?

    Hi Desigal59,
    You can use a Flat File Source adapter to get the query statement from the .sql file. When creating the Flat File Connection Manager, set the Row delimiter to a character that won’t be in the SQL statement such as “Vertical Bar {|}”. In this way, the Flat
    File Source outputs only one row with one column. If necessary, you can set the data type of the column from DT_STR to DT_TEXT so that the Flat File Source can handle SQL statement which has more than 8000 characters.
    After that, connect the Flat File Source to a Recordset Destination, so that we store the column to a SSIS object variable (supposing the variable name is varQuery).
    In the Control Flow, we can use one of the following two methods to pass the value of the Object type variable varQuery to a String type variable QueryStr which can be used in an OLE DB Source directly.
    Method 1: via Script Task
    Add a Script Task under the Data Flow Task and connect them.
    Add User::varQuery as ReadOnlyVariables, User::QueryStr as ReadWriteVariables
    Edit the script as follows:
    public void Main()
    // TODO: Add your code here
    System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
    DataTable dt = new DataTable();
    da.Fill(dt, Dts.Variables["User::varQuery"].Value);
    Dts.Variables["QueryStr2"].Value = dt.Rows[0].ItemArray[0];
    Dts.TaskResult = (int)ScriptResults.Success;
    4. Add another Data Folw Task under the Script Task, and join them. In the Data Flow Task, add an OLE DB Source, set its Data access mode to “SQL command from variable”, and select the variable User::QueryStr.
    Method 2: via Foreach Loop Container
    Add a Foreach Loop Container under the Data Flow Task, and join them.
    Set the enumerator of the Foreach Loop Container to Foreach ADO Enumerator, and select the ADO object source variable as User::varQuery.
    In the Variable Mappings tab, map the collection value of the Script Task to User::QueryStr, and Index to 0.
    Inside the Foreach Loop Container, add a Data Flow Task like step 4 in method 1.
    Regards,
    Mike Yin
    TechNet Community Support

  • Using unlinked sql command and table in a subreport

    All,
    Does CR allow using an unlinked sql command and a table in the same subreport?  I am passing the CurrentCEUserName from the main report to the sql command in the subreport (via linked parameter).  The sql command then executes a query to pass the parameter to the database (example: select myfunction('{?myparam}' from dual).  I need this to run before subreport's table query is executed. 
    This all appears to work except that the parameter passed to the sql command isn't set when the command executes.  The value is always null when the sql command is executed.  If I add the parameter to the report output it shows the expected value. 
    Also, if I have a subreport that just has a single sql command the parameter is set correctly prior to executing the command.
    any help would be appreciated.
    thanks!

    If you are looking for Crystal to run the SQL Command, then the SQL it generates itself, I think the answer is no, it won't do that.  Crystal expects all of the data sources to be linked, I believe.  I'm not sure what you would expect to happen if they are not...  However, you can make your SQL Command something like (MS SQL; sorry, it's been too long since I've used Oracle...):
    declare @result varchar(100);
    set @result = ( select myfunction('{?myparam}') );
    select * from table;
    which would run the first select calling your function, basically throw away the result (or you can do with it as needed), then return the fields from your table.
    HTH,
    Carl

  • Validation Error - An error occured executing the provided SQL Command

    Hi All,
    I am new to using SQL Server in general (2008 R2) and am trying to change the source location for multiple packages in order to obtain our data from a more reliable environment.
    I have created a copy of the target database where the data will be loaded, amended the source and target connection managers and ran through the packages to ensure they work, which many do.
    We are changing the source from a local server to a cloud based server and when running a package that literally truncates target table, selects * from source, and inserts data to target I get a validation error "An error occurred executing the provided
    SQL Command "Select *...." The connection has been disabled" and "component ADO NET Source failed validation and returned validation status "VS_ISBROKEN"".
    The table structure from the 2 sources is the same and I have even recreated the data flow tasks to ensure the metadata has updated. When selecting 100 rows or even 5,000,000 rows from source the package runs fine but will fail as above
    when selecting &* (around 9.5 million rows).
    I'm not sure if this is due to the new data source being web based or if it could be some erroneous data in the table that isn't being selected when limiting to 5 milling rows etc.
    I have spend hours trying to figure out what the issue could be (doesn't help being new to SQL Server) so any guidance would be hugely appreciated!!!
    Thanks,
    Louis.

    Hi All,
    Unfortunately I don't believe any of the above are the issues.
    Our current working project/packages run via an SQL agent job daily. To test and ensure the package in question ran outside of the agent WITHOUT changing the ADO NET Source I exported the package (that runs daily) and ran it locally,
    to which it failed.
    I then edited the select statement from 'select * from [table]' to 'select top(100) from [table] to which it ran without error.
    So in summary:
    Package will run fine if run as part of the agent job (with multiple other packages)
    Package will not run from File System when selecting * from the source table
    Package will run from File System when selecting limited rows
    Could this be something to do with permissions? The errors I get are:
    An error occurred executing the provided SQL command: "select * from [table]". The connection has been disabled.
    "component" ADO NET Source"(396") failed validation and returned validation status "VS_ISBROKEN".
    Thanks,
    Louis.

  • Mixing SQL Command parameters and UI created parameters

    Post Author: shecter
    CA Forum: Data Connectivity and SQL
    I'm using Crystal Reports XI.  I've created a report with an SQL Command - no other tables or views. I want to allow my users to be able to choose data from a dynamic parameter and have the SQL read that and spit out the results. I was able to add a parameter to the SQL using the Parameter column in the Command window. This allows my user to type in a parameter. However, when I run the report after creating a parameter using the UI (i.e. Field Explorer/Parameters/right clicking and selecting "new" and then adding the parameter to a field using the selection wizard), i first get a screen that shows me the parameter that I created in the SQL Command window, then I get a screen that shows me the UI created parameters. How can I make it show only one screen with all the parameters?  -Marc 

    Post Author: jenxia
    CA Forum: General
    SQL Command is :
    SELECT UNIQUE ContactID,  incomingAddress,applicationid,
    MediaStatus, MediaDirection, EndDateTime, StartDateTime
    FROM MMCAContactMediaViewwhere EndDateTime>= {?1-reportstarttime}  and  EndDateTime <= {?2-reportendtime}
    Order by ContactID
    Select formula using dynamic prompts as
    {Command.contactid} = {?ContactID} and{Command.applicationid} = {?ApplicationID} and{Command.incomingaddress} = {?IncomingAddress}

  • Passing Parameter from Main report to SQL command-based subreport

    I am trying to cut down the run time of my reports and have recently figured out how to write SQL commands to limit the data by filtering prior to being pulled into the reports.  However, many of my reports rely on multiple sub reports, which can cause a dramatic 'drag' on the report.
    I am trying to filter the SQL command used in my sub report by passing the group parameter, which is selected by the user in the main report, to the sub report's SQL command.  Without this parameter, the sub report has to sort through a lot more data than it would with this parameter, making the run time extremely slow.
    Any suggestions on how I can accomplish this?
    Thanks for any help you can provide,
    Marlene Allen
    Crystal Reports Developer
    Crystal Reports Professional;
    Product Type: Full;
    Product Version 11.5

    Hi Marlene,
    I don't believe you can pass a CR parameter to a Command object.
    I suggest replacing all of the Command Objects with a Stored Procedure so all of the data filtering is done server side. DB servers are much more proficient at collecting the data and filtering than CR will ever be. It will also allow you to replace subreports to also speed up your report processing. All depends on your layout of course but something to look at.
    Thank you
    Don

  • Compile a procedure /SQL file using JDBC?

    Is there a way we can compile a procedure or even a smiple SQL file using JDBC?
    Or in other words can "@ <file name with path>" be done using JDBC? Has anyone tried this before?
    I have five different databases, and i want to be able to compile my stored procedures at once on all my 5 databases. So, if we know if this is possible in JDBC?
    THanks

    right, as a matter of fact i wanted some pointers on how to run these SQL commands using JDBC.
    Like, set serveroutput on
    set feedback on
    @ filename or start filename
    show error
    etc.

  • Sql Commands for Backup and restore database

    Hi,
    What are the SQL commands used for database backup nad restore?
    Is it possible to use these command in pl/sql block or it is used only
    from sql plus?
    Thanks
    Jobin .SP

    http://download.oracle.com/docs/cd/B19306_01/backup.102/b14192/intro005.htm

  • Need advice for using Tempory tables

    Hi,
    I am soort of expert in SQL programming using MS SQL and SYBASE. But I am new in ORACLE.
    In SQL SERVER, using tempory tables are very simple. But it seems very different in ORACLE.
    1. Can I use create several different temp tables in a stored procedure?
    2. Dose the temp table has to be named as Temp_tablename?
    3. After executing the stored procedure, will those temp tables disappear automnatically? Should I manually clean them up?
    Thank you for help in advance.
    Karl

    1. Yes. You need to use Dynamic SQL within your PL/SQL code to issue any DDL command.
    2. You can name those temp tables whatever name you want.
    3. You need to issue "DROP table XXX" command to remove those temp tables. Why not use PL/SQL table within you PL/SQL code since PL/SQL is a memory construct and it will only exist during the run time of your PL/SQL code.
    Jack

Maybe you are looking for

  • Warranty and Hard Drive Self Upgrade

    According to Apple insider the hard drive in the new macbooks are easy to get to. I would like to purchase a 2.0 Duo (white) in the store (not fond of the 150 color change) that has a 80gb or 100gb hard drive and would like to get it as soon as possi

  • Delete a page with VB?

    I feel silly asking this, as it has to be a simple thing to do, but I don't see it anywhere in the documentation. How do I delete a page from an InDesign document using VB?

  • TS1363 how do i get my nano to wake while playing?

    My nano will not wake when I press the power button and will not turn off when I press the power button. What can I do to change this?

  • Frustrating skips in DVD playback

    I have verified that there are no problems in the video in FCP. I export as QuickTime Movie uncompressed video NTSC 48K/8 bit. I then burn my DVD and the result is that there are visual frame drops when playing back the DVD. I've tried all sorts of d

  • Can't access Time Machine settings when AirPort (WiFi) is on.

    Problem: My iMac (2.66 MHz Inter Core Duo) with 10.5.8 needs an upgrade to Maverick...it is connected to my home network with AirPort I have a NAS on my home network (Verbatim MediaShare 2TB) wired connected, which I have had working as a drive for T