How do I avoid writing a SQL Server query twice to avoid duplication? -



How do I avoid writing a SQL Server query twice to avoid duplication? -

i have sql query requires repeating same select statement number of times within overall query input other calculations.

how can write query define repeated select sql statement once? there method doing avoid making mistakes when repeated through query?

update: in instance info returned select expected < 100 rows in 80% of cases , max of 100-200 rows in other 20% of cases

cte , table variables both valid answers - how know 1 more appropriate alternative in situation?

if want reuse same select subquery, multiple times in same query, can utilize common table expressions (cte).

sql-server query-optimization

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -