Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Having huge number of condition in a single query will screw the performance ?

$
0
0
[b]Having huge number of condition in a single query will screw the performance ?[/b]I have a staging table which has 100 columns. I need to validate data before I insert those into destination table. All the data errors should be updated into one column called ValidationMessage.Almost all the columns have some criteria to check, Now I'm using separate update query for each validationEG :[code="sql"]Update StagingTable Set ValidationMessage = Isnull(ValidationMessage,'') + 'column 1 can contain max 100 chars'where len(column1 ) > 100Update StagingTable Set ValidationMessage = Isnull(ValidationMessage,'') + 'column 2 can contain value 1,2 or 3'where column2 not in (1,2,3)[/code]I'm thinking to have single update by using case,Eg:[code="sql"]Update StagingTable Set ValidationMessage = case when len(column1 ) > 100 then Isnull(ValidationMessage,'') + 'column 1 can contain max 100 chars' end + Case when column2 not in (1,2,3) then Isnull(ValidationMessage,'') + 'column 2 can contain value 1,2 or 3' end where len(column1 ) > 100 or column2 not in (1,2,3)[/code]So this will reduce the multiple but I'm doubting about "Having huge number of condition in a single query will screw the performance ?"sql-server-2008 tsql sql-update case sqlperformance

Viewing all articles
Browse latest Browse all 3145

Trending Articles