Comparing data size in one table to column widths in another table

I have data in a table that has a large number of columns, many of them nvarchar of varying widths.  Im trying to take that data and insert it into another table but Im getting the warning message about string or binary data being truncated.  I
suspect there is a field somewhere that is not large enough for the data.  However, I run across this often enough I would like to come up with a better solution than just eyeballing the data.
I found this example
http://www.sqlservercentral.com/Forums/Topic1115499-338-2.aspx
(credit goes to poster in the linked thread above)
Select columns
into #T
from MyDataSource;
select *
from tempdb.sys.columns as TempCols
full outer join MyDb.sys.columns as RealCols
on TempCols.name = RealCols.name
and TempCols.object_id = Object_ID(N'tempdb..#T')
and RealCols.object_id = Object_ID(N'MyDb.dbo.MyTable)
where TempCols.name is null -- no match for real target name
or RealCols.name is null -- no match for temp target name
or RealCols.system_type_id != TempCols.system_type_id
or RealCols.max_length < TempCols.max_length ;
Why a full outer join ?  Why not just a left join, since I really only want to see the matches on my source table?
When Im running this against the table im interested in, it doesnt seem to find matches between my target table and my temp table 

As an outer join of any type, that query won't work well.  For example, suppose you do a left join.  So the query begins by getting every row from tempdb.sys.columns (whether it is in #T or not).  Consider a row for a column which is not in
#T, you look for matches for rows in Mydb.sys.columns ON
on TempCols.name = RealCols.name
and TempCols.object_id = Object_ID(N'tempdb..#T')
and RealCols.object_id = Object_ID(N'MyDb.dbo.MyTable)
Notice that since the row you are considering is NOT a column in #T, the second part of the ON condition is not true, so the whole ON condition will not be true.  But this is a left join.  So the join keeps this row with NULL's in the columns coming
from the RealCols table.  Then you do the where condition, but the connections are all OR and one of the conditions is RealCols.name is null (which it is because there was no match), your output will include a row for this column in tempdb even though
this column is not in #T.  So if you use a left join, the output of this query will include a row for every column in every table in tempdb not named #T.
Similarly, if you do a right join, you get a column for every row of every table in MyDb which is not a column in dbo.MyTable.
And a full join (which you are doing above) will return a row for every column in every table in both tempdb and MyDb.
This query will sort of work if you make it an inner join.  But even then it won't find every possible cause of string or binary truncation.  For example, you are doing RealCols.max_length < TempCols.max_length.  But in sys.columns, if
you have a varchar(max) column, max_length is stored as -1.  So if a column in RealCols is varchar(50) and the same column in TempCols is varchar(max), that column will not show up as an exception, but of course, you can get truncation if you attempt
to store a varchar(max) in a varchar(50).
I would run a query more like
Create Table FooX(a int, b varchar(20), c int, d varchar(20), e int, f varchar(20), g decimal(4,0));
Select a, b, 1 as x, 'abc' as y, Cast('' as varchar(max)) As f, Cast(25.1 as decimal(3,1)) as g
into #T
from FooX;
Select 'In Real, not in or different in Temp' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From sys.columns Where object_id = Object_ID(N'FooX')
Except Select 'In Real, not in or different in Temp' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'tempdb..#T')
Union All
Select 'In Temp, not in or different in Real' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'tempdb..#T')
Except Select 'In Temp, not in or different in Real' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'FooX')
Order By name, Description;
go
Drop Table #T
go
Drop Table FooX
The output of that is
In Real, not in or different in Temp c 3 56 4 10 0 NULL
In Real, not in or different in Temp d 4 167 20 0 0 SQL_Latin1_General_CP1_CI_AS
In Real, not in or different in Temp e 5 56 4 10 0 NULL
In Real, not in or different in Temp f 6 167 20 0 0 SQL_Latin1_General_CP1_CI_AS
In Temp, not in or different in Real f 5 167 -1 0 0 SQL_Latin1_General_CP1_CI_AS
In Real, not in or different in Temp g 7 106 5 4 0 NULL
In Temp, not in or different in Real g 6 106 5 3 1 NULL
In Temp, not in or different in Real x 3 56 4 10 0 NULL
In Temp, not in or different in Real y 4 167 3 0 0 SQL_Latin1_General_CP1_CI_AS
From which you can quickly see that the differences are c, d, and e are in the real table and not the temp table, f is in both tables but the max_length is different, g is in both table, but the precision and scale are different, and x and y are in the temp
table, but not the real table.
Tom

Similar Messages

  • How do u save datas more than one table using net beans ide using JSF

    Hi,
    I am new to JSF.
    I save / delete / update / New master table using POJO (Plain Old Java Objects), database - oracle and Toplink Persistence Unit.
    How do u save data more than one table using net beans ide using JSF (I am using POJO) ?
    and also Tell me the reference book for JSF.
    Thanks in advance.
    regards,
    N.P.Siva

    SivaNellai wrote:
    I am new to JSF.
    So, I am using net beans IDE 6.1 from sun microsystem. It is a free software.No, you don't drag'n'drop if you're new to JSF. Switch to source code mode. Write code manually, with the help of IDE for the speed up.
    So, please guide me the reference books, articles. I need the basic understanding of JSF, net beans IDE.[JSF: The Complete Reference|http://www.amazon.com/JavaServer-Faces-Complete-Reference/dp/0072262400] is a good book. The [JSF specification document|http://jcp.org/aboutJava/communityprocess/final/jsr252/index.html] is also a good reading to understand what JSF is and how it works. There are also javadocs and tlddocs of Sun JSF Mojarra.

  • How to compare data cross 2 different tables in logical layer?

    Hello
    I have run into a situation where I need to bring in a new column from the status table say 'flag'. This physical column then needs to compare itself with the sales fact's code column. So if the code is '100' and above, then flag column should be '0', else flag.
    In the data models, the sales fact joins to status dimension physically and logically.
    So in the expression builder of the flag column in my BMM layer, I have something like *(case when Sales Mart. Sales Fact. status > '100' then '0' else Sales Mart. Sales Fact. flag end)*..
    However, although the syntax is correct in the expression builder, however the logical column doesn't accept that expression via 'invalid expression'.
    I think I know the problem, because flag column and status column are from different physical and logical column therefore it can't be used in the case statement at logical level. Because I tested this theory with '*(case when Sales Mart. Sales Fact. status > '100' then '0' end)'* and it accepted it.
    Nonetheless, I can't modify the database table nor the ETL to put both columns in one table, nor am I allowed to defined such expression at answers.
    Is there a way I can base the result of flag column on the data of status column from a different logical table?
    Please advice!
    Thanks

    Follow these steps:
    1) Bring your first time period in your main report.  This will be your first query.
    2) Bring your second time period in a subreport.  This will be your second query.
    3) Bring the values from your subreport into your main report using shared variables.
    4) Lastly, compare the results using formulas in your main report.
    I hope this information proves useful.
    Regards,
    Zack H.

  • Compare date ranges in two tables

    Hello,
    I'm trying to figure out a way of comparing the range of dates between two date columns from a single row in one table, to the range of dates from multiple rows in a related table.
    t1 (t1_id, absent_start_date, absent_stop_date)
    t2 (t2_id, t1_id, cover_start_date, cover_end_date)
    t2 has multiple rows for each row in t1
    I need to select rows from t1, in which the set of days for rows in t2 do not match the set of days between absent_start_date and absent_stop_date.
    For example, assume this row in t1:
    1, '10/08/2007', '15/08/2007'
    The set of days would be 10/08/07,11/08/07,12/08/07,13/08/07,14/08/07,15/08/07
    and these rows in t2
    1, 1, '10/08/2007', '11/08/2007'
    2, 1, '12/08/2007', '12/08/2007'
    3, 1, '14/08/2007', '15/08/2007'
    The set of days would be 10/08/07,11/08/07,12/08/07,14/08/07,15/08/07
    In this case, the related rows in t2 do not cover the same date range as the master row in t1, and so I need to select this row from t1 somehow.
    Any ideas anyone?
    Thanks.

    I am not sure about the exact output you want, but the next query will give you all gaps in the periods, so the presence of a row in this output may be enough?
    SQL> create table t1
      2  as
      3  select 1 t1_id, date '2007-08-10' absent_start_date, date '2007-08-15' absent_stop_date from dual union all
      4  select 2, date '2007-09-01', date '2007-09-10' from dual
      5  /
    Tabel is aangemaakt.
    SQL> create table t2
      2  as
      3  select 1 t2_id, 1 t1_id, date '2007-08-10' cover_start_date, date '2007-08-11' cover_stop_date from dual union all
      4  select 2, 1, date '2007-08-12', date '2007-08-12' from dual union all
      5  select 3, 1, date '2007-08-14', date '2007-08-15' from dual union all
      6  select 4, 2, date '2007-09-03', date '2007-09-05' from dual union all
      7  select 5, 2, date '2007-09-07', date '2007-09-08' from dual
      8  /
    Tabel is aangemaakt.
    SQL> select  *
      2    from ( select t2.t1_id
      3                , lag(t2.end_date+1,1,t1.absent_start_date) over (partition by t2.t1_id order by t2.start_date) gap_start_date
      4                , t2.start_date-1 gap_end_date
      5             from t1
      6                , ( select t1_id
      7                         , cover_start_date start_date
      8                         , cover_stop_date end_date
      9                      from t2
    10                     union all
    11                    select t1_id
    12                         , absent_stop_date+1
    13                         , absent_stop_date+1
    14                      from t1
    15                  ) t2
    16            where t1.t1_id = t2.t1_id
    17         )
    18   where gap_start_date <= gap_end_date
    19   order by t1_id
    20       , gap_start_date
    21  /
                                     T1_ID GAP_START_DATE      GAP_END_DATE
                                         1 13-08-2007 00:00:00 13-08-2007 00:00:00
                                         2 01-09-2007 00:00:00 02-09-2007 00:00:00
                                         2 06-09-2007 00:00:00 06-09-2007 00:00:00
                                         2 09-09-2007 00:00:00 10-09-2007 00:00:00
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • How to Compare Data length of staging table with base table definition

    Hi,
    I've two tables :staging table and base table.
    I'm getting data from flatfiles into staging table, as per requirement structure of staging table and base table(length of each and every column in staging table is 25% more to dump data without any errors) are different for ex :if we've city column with varchar length 40 in staging table it has 25 in base table.Once data is dumped into staging table I want to compare actual data length of each and every column in staging table with definition of base table(data_length for each and every column from all_tab_columns) and if any column differs length I need to update the corresponding row in staging table which also has a flag called err_length.
    so for this I'm using cursor c1 is select length(a.id),length(a.name)... from staging_table;
    cursor c2(name varchar2) is select data_length from all_tab_columns where table_name='BASE_TABLE' and column_name=name;
    But we're getting data atonce in first query whereas in second cursor I need to get each and every column and then compare with first ?
    Can anyone tell me how to get desired results?
    Thanks,
    Mahender.

    This is a shot in the dark but, take a look at this example below:
    SQL> DROP TABLE STAGING;
    Table dropped.
    SQL> DROP TABLE BASE;
    Table dropped.
    SQL> CREATE TABLE STAGING
      2  (
      3          ID              NUMBER
      4  ,       A               VARCHAR2(40)
      5  ,       B               VARCHAR2(40)
      6  ,       ERR_LENGTH      VARCHAR2(1)
      7  );
    Table created.
    SQL> CREATE TABLE BASE
      2  (
      3          ID      NUMBER
      4  ,       A       VARCHAR2(25)
      5  ,       B       VARCHAR2(25)
      6  );
    Table created.
    SQL> INSERT INTO STAGING VALUES (1,RPAD('X',26,'X'),RPAD('X',25,'X'),NULL);
    1 row created.
    SQL> INSERT INTO STAGING VALUES (2,RPAD('X',25,'X'),RPAD('X',26,'X'),NULL);
    1 row created.
    SQL> INSERT INTO STAGING VALUES (3,RPAD('X',25,'X'),RPAD('X',25,'X'),NULL);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * FROM STAGING;
            ID A                                        B                                        E
             1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX
             2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX
             3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXX
    SQL> UPDATE  STAGING ST
      2  SET     ERR_LENGTH = 'Y'
      3  WHERE   EXISTS
      4          (
      5                  WITH    columns_in_staging AS
      6                  (
      7                          /* Retrieve all the columns names for the staging table with the exception of the primary key column
      8                           * and order them alphabetically.
      9                           */
    10                          SELECT  COLUMN_NAME
    11                          ,       ROW_NUMBER() OVER (ORDER BY COLUMN_NAME) RN
    12                          FROM    ALL_TAB_COLUMNS
    13                          WHERE   TABLE_NAME='STAGING'
    14                          AND     COLUMN_NAME != 'ID'
    15                          ORDER BY 1
    16                  ),      staging_unpivot AS
    17                  (
    18                          /* Using the columns_in_staging above UNPIVOT the result set so you get a record for each COLUMN value
    19                           * for each record. The DECODE performs the unpivot and it works if the decode specifies the columns
    20                           * in the same order as the ROW_NUMBER() function in columns_in_staging
    21                           */
    22                          SELECT  ID
    23                          ,       COLUMN_NAME
    24                          ,       DECODE
    25                                  (
    26                                          RN
    27                                  ,       1,A
    28                                  ,       2,B
    29                                  )  AS VAL
    30                          FROM            STAGING
    31                          CROSS JOIN      COLUMNS_IN_STAGING
    32                  )
    33                  /*      Only return IDs for records that have at least one column value that exceeds the length. */
    34                  SELECT  ID
    35                  FROM
    36                  (
    37                          /* Join the unpivoted staging table to the ALL_TAB_COLUMNS table on the column names. Here we perform
    38                           * the check to see if there are any differences in the length if so set a flag.
    39                           */
    40                          SELECT  STAGING_UNPIVOT.ID
    41                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_A
    42                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_B
    43                          FROM    STAGING_UNPIVOT
    44                          JOIN    ALL_TAB_COLUMNS ATC     ON ATC.COLUMN_NAME = STAGING_UNPIVOT.COLUMN_NAME
    45                          WHERE   ATC.TABLE_NAME='BASE'
    46                  )       A
    47                  WHERE   COALESCE(ERR_LENGTH_A,ERR_LENGTH_B) IS NOT NULL
    48                  AND     ST.ID = A.ID
    49          )
    50  /
    2 rows updated.
    SQL> SELECT * FROM STAGING;
            ID A                                        B                                        E
             1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX                Y
             2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX               Y
             3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXHopefully the comments make sense. If you have any questions please let me know.
    This assumes the column names are the same between the staging and base tables. In addition as you add more columns to this table you'll have to add more CASE statements to check the length and update the COALESCE check as necessary.
    Thanks!

  • Data loading from one table to another

    Hi,
    I want to load some data from a temp table to a master table. The master is having 40million records and the temp table is having 23 million records. Master table is having around 50 columns and we are adding 4new columns and the temp table is having 5columns. The data for these 4new columns are available in the temporary table also the employee column is there in common to these two table.
    I used a stored procedure to load the data, whcih uses a cursor. But its taking more that 6hours to load.
    Can any one suggest me a good technique to load data faster?
    Thanks,
    Santhosh.

    hi consider this case scenario which matches with yours.
    first of all you have to update not insert in master table.
    master table = emp with columns (emp_id, emp_name, emp_designation)
    to this original master table you added two more columns emp_salary, emp_department
    so now your master table looks like emp_id, emp_name, emp_designation, emp_salary, emp_department
    but when you do select * from master table, the last two columns salary & department are blank.
    Now you have another temp table with folllowing columns (emp_id, emp_salary, emp_department)
    now emp_id is common to master & temp tables & you want to put values from temp table into master tables? I think this is what ur trying to do..
    so for the above case the query i would write is
    update master_table m set m.emp_salary=(select t.emp_salary from temp_table t where
    t.emp_id=m.emp_id);
    commit;
    Regds.

  • Error while data shifting from one table to another table

    i have two tables.
    in one table i dont have constraints.in anothe rtable i have constraints.
    my requiremnt is i have to shift data from unconstrained table to constrained table
    while shifting data any constaint violation is there system hasto raise error by specifying the error
    in below example it should be ename,esal values not null.
    i tried with save exception but it gives only error.i want error by mentiong that column names also ie ename,esal is not null
    if ename value only null then it should be give ename is null
    create table tablea (eno number(10), ename varchar2(20) not null, esal number(5) not null)
    create table tabl (eno number(10), ename varchar2(20) , esal number(5) )
    DECLARE
    TYPE tabl_tab IS TABLE OF tabl%rowTYPE;
    tab tabl_tab;
    -- create an exception handler for ORA-24381
    ERRORS NUMBER;
    dml_errors EXCEPTION;
    PRAGMA EXCEPTION_INIT (dml_errors, -24381);
    BEGIN
    SELECT *
    BULK COLLECT INTO tab
    FROM tabl
    WHERE rownum<=2;
    -- add '_SR' to the job_id of the most senior employees
    FORALL i IN tab.FIRST .. tab.LAST SAVE EXCEPTIONS
    insert into tablea values tab(i);
    EXCEPTION
    WHEN dml_errors
    THEN
    rollback ; --roll backs all the good records updation
    -- Now we figure out what failed and why.
    ERRORS := SQL%BULK_EXCEPTIONS.COUNT;
    DBMS_OUTPUT.put_line ('Number of statements that failed: ' || ERRORS);
    FOR i IN 1 .. ERRORS
    LOOP
    DBMS_OUTPUT.put_line ( 'Error #'
    || i
    || ' occurred during '
    || 'iteration #'
    || SQL%BULK_EXCEPTIONS (i).ERROR_INDEX
    DBMS_OUTPUT.put_line ( 'Error message is '
    || SQLERRM
    (-SQL%BULK_EXCEPTIONS (i).ERROR_CODE)
    END LOOP;
    END;
    how to implement that.

    it should give error as ename column is not null

  • Estimate 1 Row data size in a table

    Hello I have a table like below I want to know 1 record size in KB
    Create table test(
    Id int,
    Name nvarchar(5),
    File nvarchar(max),
    Createddate datetime,
    User varchar(20))
    Can you tell me in this way
    int =
    Name=
    File=
    Createdate=
    User
    So it will help me in future to calculate myself.

    HI,
    try this.
    DECLARE  @sql nvarchar(max),@clmns nvarchar(max),@table nvarchar(100),@ln varchar(max)
    SET @table = 'REGIONS'
    SELECT @clmns =
    STUFF((
                SELECT ', ['+name+']' as 'data()' FROM
                        SELECT name FROM sys.columns where object_id = object_id(@table)
                    ) a
                FOR XML PATH(''),TYPE
            ).value('.','NVarchar(max)'),1,2,''),
        @ln =
    STUFF((
                SELECT '+ ' +ln as 'data()' FROM
                        SELECT CASE WHEN collation_name is null THEN CAST(max_length as Varchar(10)) ELSE 'LEN('+name+')'END as ln FROM sys.columns where object_id = object_id(@table)
                    ) a
                FOR XML PATH(''),TYPE
            ).value('.','NVarchar(max)'),1,2,'')
    PRINT @ln
    SET @sql = 'SELECT '+@clmns+','+@ln+' as ln FROM '+@table+' r'
    EXEC (@sql)
                

  • Compare two fields of one table in selection.

    Dear Experts,
    I want to compare two fields of a table and make selection according to this.
    Ex: simply i want to select the rows from table mard where mard-labst>mard-insme. Could you write me the code to make this selection.

    Yes, Thomas,
    Its working:
    Sample code:
    data: begin of itab occurs 0,
          matnr type matnr,
          ernam type ernam,
          end of itab.
    select matnr ernam
           into table itab
           from mara where brgew > mara~ntgew.
    loop at itab.
      write: itab-matnr.
    endloop.
    Or,
    Try with inner join once.
    Its working: Sample code.
    data: begin of itab occurs 0,
          matnr type matnr,
          ernam type ernam,
          end of itab.
    select p~matnr q~ernam
           into table itab
           from mara as p
           inner join mara as q
           on p~brgew > q~ntgew.
    loop at itab.
      write: itab-matnr.
    endloop.
    Thanks,
    Naveen.I

  • Implement the Logic in Mapping to select, compare and update on one table

    Hi All,
    We have a Sales Order history table *(HISTORY_TABLE)* and we want implement the below logic in warehouse builder where we are using only one table for checking the condition and selecting the records to update in the HISTORY_TABLE.
    Like
    SELECT ORDERNO, LINENO, ORDERTYPE FROM HISTORY_TABLE A
    WHERE EXISTS IN (SELECT ‘X’
    FROM HISTORY_TABLE B
    WHERE A. ORDERNO = B. ORDERNO
    AND   A. LINENO = B. LINENO
    AND   A.ORDERTYPE = B. ORDERTYPE
    HAVING MAX (B.PDDJ) = 0)
    Thanks in advance.

    Hi,
    you can implement this as
    SELECT A.ORDERNO, A.LINENO, A.ORDERTYPE FROM HISTORY_TABLE A,
    (SELECT ORDERNO,LINENO,ORDERTYPE FROM HISTORY_TABLE GROUP BY ORDERNO,LINENO,ORDERTYPE HAVING MAX(PDDJ) = 0) B
    WHERE A.ORDERNO = B.ORDERNO
    AND A.LINENO = B.LINENO
    AND A.ORDERTYPE = B.ORDERTYPE Use Aggregator (group by with having) and then Joiner
    Regards,
    Oleg

  • Data Pump -Importing one table index

    Is it possible to import one table index alone(any table ex emp ) .If it can be how should the param should look like ..
    Thanks and Regards
    harris

    I can't think of anything that would prevent this from working. You just need to make sure that the large table does not have any ref constraints, or other associations with the other tables that may get screwed up while the other users are using the database.
    Dean

  • Is there any easy way to compare LIKE Addresses from one table, which contains 3rd party data, to another table, our database source

    We have a 3rd party that is supplying us data and we need to compare the addressing between the 3rd party data to our source database addressing. I'd like to make it somewhat flexible meaning I'd like to somehow use the LIKE comparison rather than comparing
    the exact address values. (I have noticed that the 3rd party addressing sometime has a leading <space> at the beginning of the address...why I'd prefer to use LIKE)
    Is there any easy way to do this? Or does this dictate using a CURSOR and processing through the CURSOR of 3rd party data and plugging in the address LIKE as dynamic SQL?
    Please let me know your thoughts on this and I appreciate your review and am hopeful for a reply.

    Yes, it's possible and there are a variety of options but it's may not be for the faint of heart.
    The last time I did it, I ended up taking several passes at the data.
    1st pass was a straight up comparison with no modifications or functions.
    2nd pass was the same but with all special characters removed.
    3rd pass involved splitting the numeric portion of address and comparing just the street numbers and used a double meta-phone function (kind of like a soundex on steroids) to compare the street names.
    Jason Long

  • Data Loading from one table to another in the Same Database based on conditions .

    Hi ALL ,
    I have 2 tables Products and Product_info .
    Product_info table Product_id is Primary key but not an identity column so auto increment of number needs to be performed from the Package only .
    Requirement is :
    IF the Product_ID is = 20 and Date lies in the previous month not the current month in the Products table then 
    insert into the Product_info table based on below mentioned information .
    1.If the Name  has tap then ignore it completely don't perform any insert for it.
    2.If the Name has Zork in it then perform 2 inserts in the Product_info table having Product_info_id's 1 and 2 .
    3.If the Name doesn't contains Zork or tap insert it in the Product_info table having Product_info_id 4.
    Very new to SSIS package development it will be helpful if you can provide detailed information .
    Source Table (Products table )
    ID
    NAME
    Product_ID
    Date 
    Area_ID
    1
    P_tap_rus
    20
    13-01-2014
    3
    2
    Enc_sap_top
    10
    15-01-2014
    4
    3
    Yorl
    20
    05-02-2014
    5
    4
    zork
    20
    20-01-2014
    6
    5
    fadbt
    10
    22-01-2014
    6
    6
    xyzzz_oprt
    20
    28-01-2014
    5
    7
    def_type_ru
    20
    06-02-2014
    2
    8
    acd_inc_tup
    10
    07-02-2014
    3
    9
    bnf_dlk_fbg
    20
    03-02-2014
    4
    10
    rtyui_vnmghj_sfdl
    10
    12-01-2014
    5
    11
    wlwf_10103_123
    10
    04-02-2014
    9
    Destination table  (Product_info)
    Porduct_ID
    ID
    Area_ID 
    Product_info_ID
    Column1
    1
    3
    5
    4
    As NameString doesn’t contain Zork or Tap 
    2
    4
    3
    1
    As Id is 4 so 2 inserts one for 1 and other for 2 in the Product_info_id column
    3
    4
    3
    2
    4
    6
    5
    4
    5
    10
    5
    4
    6
    11
    9
    4
    Please let me know if any other information is required .
    Thanks
    Priya

    Hi Priya,
    You mentioned this was coming from two tables right? I believe I would try to perform the transformations with T-SQL in my source (If this is a possibility for you). Below is an example of something you could do.
    WITH CTE
    AS
    SELECT ID, Product_ID, [Date], Area_ID,
    CASE
    WHEN Name like '%Zork%' THEN 1
    ELSE 4
    END AS Product_Info_ID
    FROM [YourTable]
    WHERE Product_ID = 20 and MONTH([DATE]) = MONTH(DATEADD(MM, -1, GETDATE())) AND NAME NOT LIKE '%tap%'
    SELECT *
    FROM CTE
    UNION
    SELECT ID, Product_ID, [Date], Area_ID, '2' AS Product_Info_ID
    FROM CTE WHERE Product_Info_ID = 1
    I hope this helps, Regards.

  • Data retrieve from one table control to another table control

    Hi all,
    I had an requirement like to create Two table controls.
    for first Table control i had an sel field defined as 'MARK'.
    when i check the row in the first table control think it  is header data for sales order .
    all the item details have to retrieve in the second table control.
    This is my requirement, i am not able to trigger when selecting the row in table control.
    will anybody had an experience like this.
    Regards,
    Madhavi

    Hi Madhavi,
    If  we need the case to display header and item as mentioned in 2 table controls....
    we can display in table control 2/item only (the line items of the one selected in the table control 1 or the header )...so ,at a time we need to display line items for only 1 header ....
    so ...first disable the selections/multiple selections to disable the row selector
    We have already declared a field type C to capture the value for the field selector...so we can convert this field to a radio button and then assign a function code to the radio button at screen level
    Whenever you click on the radio button ..immediately the function code is triggered..then in PAI ..we can check and find the header record with 'X' and populate the data for the table control 2
    Hope it helps
    Regards
    Byju

  • Compare dates between 2 different rows and columns

    I'm having problems figuring this out.  Here is an example table:
    What I need to be able to find is any records where the Discontinue_Date is greater than the Effective_Date on the next row for a given Customer ID and Part_ID.  This is a customer pricing table so the Discontinue_Date of row 53 for example should never
    be greater than the Effective_Date of row 54130, these are the records I'm looking to find.  So I'm looking for a SELECT query that would look for any records where this is true.  Obviously the last Discontinue_Date row for a Customer_ID will not
    have a next row so I wouldn't want to return that. 
    Let me know if anyone has any ideas or if more clarification is needed, I've been struggling with how to get started on this!!
    Thanks very much in advance!
    JIM

    >> I'm having problems figuring this out. Here is an example table: <<
    NO! Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data
    should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. You pasted a colored picture that we have to transcribe into DDL to do your job for you. But you also do not know basic terminology! 
    Rows are not records, since tables are sets, there is no “next row” concept, rows do not have physical row numbers, etc.  Your mindset is still in a spreadsheet and not RDBMS. 
    >> What I need to be able to find is any records [sic] where the discontinuation_date is greater than the effective_date on the next row for a given customer_id and part_id. <<
    Why not prevent bad data instead of trying to kludge and report it after the fact? 
     Consider this self-reference trick to prevent gaps in a timeline of events:
    CREATE TABLE Events
    (event_id CHAR(10) NOT NULL,
    previous_event_end_date DATE NOT NULL
    CONSTRAINT Chained_Dates
    REFERENCES Events (event_end_date),
    event_start_date DATE NOT NULL,
    event_end_date DATE UNIQUE, -- null means event in progress
    PRIMARY KEY (event_id, event_start_date),
    CONSTRAINT Event_Order_Valid
    CHECK (event_start_date <= event_end_date),
    CONSTRAINT Chained_Dates 
    CHECK (DATEADD(DAY, 1, previous_event_end_date) = event_start_date).
    << other stuff for this event >>
    -- disable the Chained_Dates constraint
    ALTER TABLE Events NOCHECK CONSTRAINT Chained_Dates
    -- insert a starter row
    INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
    VALUES ('Foo Fest', '2010-01-01', '2010-01-02', '2010-01-05');
    -- enable the constraint in the table
    ALTER TABLE Events CHECK CONSTRAINT Chained_Dates
    -- this works
    INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
    VALUES ('Glob Week', '2010-01-05', '2010-01-06', '2010-01-10');
    -- this fails
    INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
    VALUES ('Snoob', '2010-01-09', '2010-01-11', '2010-01-15'); 
    Since you did not write DDL for us, you can use this idiom to get a working schema. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for