Discussion Locked

Dynamic Views in MSSQL Server

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
MS-SQLServer provides varchar datatype of maximum size 8000 characters. The problem I am facing is that I am creating a dynamic view whose statements runs more than 8000 characters and I am not able to hold more than 8000 characters in a local variable whose data type is varchar(8000). SQL Server does not allow TEXT datatype as local variable which if allowed would solve the problem.How do I generate a dynamic view which is more that 8000 characters?

3 replies

by glen_mcleod

Try putting each of your clauses in separate variables then executing them as a unit.

Exec (@SelectClause + @FromClause + @WhereClause + @GroupByClause + @OrderByClause + @HavingClause)

I've never done it with something as big as what you describe, but this is relatively simple and worth a try.

Glen

This discussion is closed to new replies.