code_junkie

How to retrieve value and use it in stored procedure in one SQL query

Nov 13th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. cmd.CommandType = CommandType.Text;
  2. cmd.Parameters.AddWithValue("@id", ...); // your id arg
  3. cmd.Parameters.AddWithValue(... , ...); // your other args...
  4. cmd.CommandText = @"
  5. DECLARE @TaskType int -- or whatever
  6.  
  7. SELECT @TaskType = // some existing query based on @id
  8.  
  9. EXEC getrecords @TaskType, ...
  10. ";
  11.  
  12. CREATE FUNCTION dbo.TaskType()
  13. Returns int
  14. SELECT ... stuff that gets task type
  15. END
  16.  
  17. DECLARE tasktype int
  18.  
  19. SELECT tasktype = dbo.TaskType
Add Comment
Please, Sign In to add comment