Viraat Saxsena
Viraat Saxsena

Reputation: 53

SQL server query : how to check value within range

In application I am working on.

I have to input from user through excel and first put it in temporary sql table & then from temporary table to final target table.

My query is failing while putting data from temporary table to target table. Because some values present in temporary table are out of range of columns in target table.

How can I check if values present in temporary table are within range of column of target table?

I have to check like this

20 < len(temporary_table.column1) < 50

or is there any better way

Upvotes: 1

Views: 2652

Answers (2)

A_kat
A_kat

Reputation: 1527

Extending on the above answer you can just use col_length instead of hard coding the value on the target column. This makes it more automated and less prone to mistakes (entering a value mistakenly)

  where len(temporary_table.column1) <= COL_LENGTH ( 'target_table' , 'column1' )   

Upvotes: 0

Rahul Neekhra
Rahul Neekhra

Reputation: 810

If you are using SQL server you can use below query for data checking.

temporary_table.column1 between 20 and 50

If you are looking based on the column max length. For example, your columns have datatype varchar(100) then you can use the condition like this

where len(temporary_table.column1)<=100

Upvotes: 1

Related Questions