1
Answer

How can I use order by in dynamic query?

Mani Kandan

Mani Kandan

8y
227
1
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?
  1. DECLARE @StartRowNum varchar(10)  
  2. DECLARE @EndRowNum varchar(10)  
  3. DECLARE @SortColumn varchar(100)   
  4. DECLARE @TransId varchar(100)   
  5.   
  6. SET @SortColumn = 'AgencyName asc'  
  7. SET @TransId = 1481143433  
  8. SET @EndRowNum = 50  
  9. SET @StartRowNum = 0  
  10.   
  11. begin  
  12.   
  13. select  ROW_NUMBER() over (order by @SortColumn )  AS RowNum, tempID,ProgramId,ChannelId,Date_DL,StartTime,EndTime,Viewers,            
  14.   Tx,TVR,CVR,DVR,            
  15.   Details_Id,            
  16.    MastersId,BrandsId,ItemsId,Note,PaidForOrProp,Verbal,Indexes,Seconds,            
  17.      GradesId,ChannelName,CountryName,WebSiteName,ProductionName,BrandName,ItemName,            
  18.      Product_company_id,CompanyName,ProductGroupsId,            
  19.      SectorsId,SubSectoresId,AgenciesId,GroupName,SectorName,SubsectoreName,             
  20.      AgencyName,agencyID,QualityGrade,CPH_DL,CPH_UN,Country_CPH,Country_UN,            
  21.      Web_CPH,Web_UN,            
  22.  AdFactor,Duration_Factor,DaypartName,DaypartId,DaypartFactor,CinemaFactor,DigitalFactor,MediaValue from             
  23.  dbo.MonitorExposureFinal WHERE Trans_Id = @TransId   
  24.  end  
Answers (1)
0
kevint
NA 54 0 20y
Try this. " Salamander .NET Linker and mini-deployment tool allows you to link .NET assemblies together into a single file, and to deploy your application without installation of the whole Microsoft .NET Framework. The linker selectively links MSIL code putting together only the required classes and methods, and it is capable of linking into the Microsoft .NET framework class libraries. The mini-deployment tool then builds a minimum set of the Microsoft .NET runtime to ship with your application. This usually results in installation size of a few mega bytes, rather than tens of mega bytes, and the installation takes much less time without rebooting machines. The mini-deployed application can be launched directly from a CD, absolutely without copying files or adding registry entries." Regards KevinT
0
erwache
NA 4 0 20y
thanks for your replies.. i just thought, that it would be possible, to bind the methods and modules which i need into the .exe so that the exe grows, but obviously it is not possible - what a pity thx maschka
0
spgilmore
NA 591 0 20y
Dynamic and static binding are terms of how the libraries of the runtime are loaded at runtime. Neither of these have to do with linking runtime libraries inside the executable.
0
vitenyi_i
NA 38 0 20y
In the same way that you couldn't run a program coded to the Win API on a non-Windows machine, a program coded to the .NET framework needs the .NET framework.