Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
allend2010
Starting Member
28 Posts |
Posted - 2002-10-31 : 11:27:38
|
| I have a very large SQL statement that I am running in a stored procedure and I want to be able to put part of the statement into a string format so that I can biuld just that part of it in a loop. For example:DECLARE @varSQL VARCHAR(1024)SET @varSQL = 'COUNT(CASE WHEN ((Weight / 16) < 15) AND (WeightCat = 0 OR WeightCat = 3) THEN PackID END)' and then in the select statement useSELECT @varSQL FROM... I know that I can put the entire statement into a string and then execute it but it is not practical for me to do this in this case becuase there are lots of other criteria that I need to include as well. Does anybody happen to know a way in which this can be accomplished? Any help would be greatly apprecieated. Thanks!-AD |
|
|
1fred
Posting Yak Master
158 Posts |
Posted - 2002-10-31 : 11:32:42
|
| You will need dynamic SQL, make a quick search on this site, it is one of the most popular question asked! |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-10-31 : 13:17:57
|
| As you don't want to use dynamic sql for the whole query can you put a result into a temp table then run this part as dynamic sql on that.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|