Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Declare @WhereClause nvarchar(max) = 'CityID=1 and CategoryID in(select CategoryID form Category where ParentCategoryID=3';
  2. select CONVERT(bit, @WhereClause) as Test
  3.  
  4. Msg 245, Level 16, State 1, Line 3
  5. Conversion failed when converting the varchar value 'CityID=1 and CategoryID in(select CategoryID form Category where ParentCategoryID=3' to data type bit.
  6.  
  7. DECLARE @CityID AS SMALLINT
  8. DECLARE @ParentCategoryID AS SMALLINT
  9. Declare @WhereClause nvarchar(max)
  10. DECLARE @SQLQuery AS NVARCHAR(max)
  11.  
  12. SET @CityID = 1
  13. SET @ParentCategoryID = 3
  14.  
  15. SET @WhereClause = 'CityID = ' + CAST(@CityID AS NVARCHAR(10)) +
  16. ' and CategoryID in(select CategoryID form Category where ParentCategoryID = '
  17. +CAST(@ParentCategoryID AS NVARCHAR(10)) +')'
  18.  
  19. SET @SQLQuery = 'SELECT * FROM YourTable WHERE ' + @WhereClause
  20.  
  21. EXECUTE(@SQLQuery)
  22.  
  23. Declare @WhereClause nvarchar(max) = 'TRUE'
  24. select convert( bit, @WhereClause) as Test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement