Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @WhereClause nvarchar(max) = 'CityID=1 and CategoryID in(select CategoryID form Category where ParentCategoryID=3';
- select CONVERT(bit, @WhereClause) as Test
- Msg 245, Level 16, State 1, Line 3
- Conversion failed when converting the varchar value 'CityID=1 and CategoryID in(select CategoryID form Category where ParentCategoryID=3' to data type bit.
- DECLARE @CityID AS SMALLINT
- DECLARE @ParentCategoryID AS SMALLINT
- Declare @WhereClause nvarchar(max)
- DECLARE @SQLQuery AS NVARCHAR(max)
- SET @CityID = 1
- SET @ParentCategoryID = 3
- SET @WhereClause = 'CityID = ' + CAST(@CityID AS NVARCHAR(10)) +
- ' and CategoryID in(select CategoryID form Category where ParentCategoryID = '
- +CAST(@ParentCategoryID AS NVARCHAR(10)) +')'
- SET @SQLQuery = 'SELECT * FROM YourTable WHERE ' + @WhereClause
- EXECUTE(@SQLQuery)
- Declare @WhereClause nvarchar(max) = 'TRUE'
- select convert( bit, @WhereClause) as Test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement