• shravan.gavva (11/20/2013)


    create table table1

    (

    data_value varchar (50),

    sql_data_type varchar (50)

    )

    insert into table1(data_value,sql_data_type)

    values ('11/02/2013', 'DATE')

    insert into table1(data_value,sql_data_type)

    values ('', 'DATE')

    insert into table1(data_value,sql_data_type)

    values (11.3, 'decimal')

    insert into table1(data_value,sql_data_type)

    values ('not assigned', 'DATE')

    insert into table1(data_value,sql_data_type)

    values (null, 'varchar')

    insert into table1(data_value,sql_data_type)

    values ($, 'varchar')

    From these information i need to check wether data_value follow the sql_data_type shown data type.If not they should be moved to another table.

    UGH. With what you have here you are almost forced to use a loop/cursor to read this row by agonizing row with a try/catch block inside each iteration.

    Let's consider a couple other real world issues with dates. You have '11/02/2013'. This is fine and will be able to be cast a date with most settings. But what about if you dmy instead of mdy. '13/02/2013' is perfectly valid IF your dateformat is dmy but fails if you dateformat is mdy.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/