TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhilash J A
530
2.4k
600.5k
How can I use order by in dynamic query?
Oct 18 2016 5:06 AM
Hello everyone,
From this below query, Order by can not working when I am passing parameter @SortColumn. But it working directly passing value. For eg, if I am giving
AgencyName asc
instead of @SortColumn. Its working fine. How to solve this issue when I am passing parameter?
DECLARE
@StartRowNum
varchar
(10)
DECLARE
@EndRowNum
varchar
(10)
DECLARE
@SortColumn
varchar
(100)
DECLARE
@TransId
varchar
(100)
SET
@SortColumn =
'AgencyName asc'
SET
@TransId = 1481143433
SET
@EndRowNum = 50
SET
@StartRowNum = 0
begin
select
ROW_NUMBER() over (
order
by
@SortColumn )
AS
RowNum, tempID,ProgramId,ChannelId,Date_DL,StartTime,EndTime,Viewers,
Tx,TVR,CVR,DVR,
Details_Id,
MastersId,BrandsId,ItemsId,Note,PaidForOrProp,Verbal,Indexes,Seconds,
GradesId,ChannelName,CountryName,WebSiteName,ProductionName,BrandName,ItemName,
Product_company_id,CompanyName,ProductGroupsId,
SectorsId,SubSectoresId,AgenciesId,GroupName,SectorName,SubsectoreName,
AgencyName,agencyID,QualityGrade,CPH_DL,CPH_UN,Country_CPH,Country_UN,
Web_CPH,Web_UN,
AdFactor,Duration_Factor,DaypartName,DaypartId,DaypartFactor,CinemaFactor,DigitalFactor,MediaValue
from
dbo.MonitorExposureFinal
WHERE
Trans_Id = @TransId
end
Reply
Answers (
1
)
Populating non-English characters from SQL Server to SSRS
How Manage 2 Crores of data in MS-SQL