i require to run seperate query statements using dynamic strings as such
@TOTALRECORDS INTEGER =0 OUTPUT,
@SubCategoryID INT =0
set @WHERECLAUSE =' (Products.CategoryID = @SubCategoryID) '
set @TOTALRECORDS ='count(*) FROM Products WHERE (Products.CATEGORYID=@SubCategoryID )'
SET @sql = 'SELECT *
FROM
(SELECT [ProductID],[VendorName],
Products.[CategoryID],Products.[Category],
ROW_NUMBER() OVER(ORDER BY @sortExpression ) as RowNum FROM Products ' + @WHERECLAUSE + ' ) AS EmpInfo '
Execute sp_Executesql @SQL
I cannot get it to return the output value ?
Muhammad Imran AnsariPosted Jan 28, 2022, 10:02 PM
Nitin SontakkePosted Jan 19, 2022, 4:51 AM
peterPosted Jan 19, 2022, 1:07 AM
Nitin SontakkePosted Jan 16, 2022, 4:46 AM
Is the above posted code part of a stored procedure? If yes, it is better to show entire stored procedure, may be removing irrelevant part to the question.
Where is @sortExpression coming from?
Which part of null you intend to handle? For example, do you want all products if @SubcategoryId is null? If yes, there is better way to handle it. You don't necessary need a dynamic SQL.
For example, you can have WHERE clause as follows:
where Products.CategoryId = isnull(@CategoryId, Products.CategoryId)
In above case all products will be selected if @CategoryId is null.
Nitin SontakkePosted Jan 15, 2022, 6:51 PM
peterPosted Jan 15, 2022, 3:49 PM
There is a problem with this site.It frequently does not allow editing and pasting text on reply?
i use dynamic string because of variable data set on condition of null statements and pagation as described.
Yes,its for pagation purpose therefore cannot get record count from returned datarows only a subset value.
Not certain of SQL version operating as i have multiple versions in existance on system. I think they are causing connection problems; for instance i am unable to test performance of SP from the designer window? As it says file not found or incompatible datafile?
I believe the location is displaces and i cannot reset using the configstring settings per norm.Although the Data retrieval operates fine!
If i remove the quote marks i cannot SET the code unless i use a SELECT clause. When i want to append to the query on a where filter on condition statement action.
peterPosted Jan 15, 2022, 3:33 PM
I am unable to respond?
Nitin SontakkePosted Jan 15, 2022, 5:11 AM