Write a sql query to sort on different column name according to the parameters passed in the function?
Answer / Shailja Singh
In SQL Server, you can dynamically build a SQL query based on the passed parameter to sort on a different column. Here's an example using dynamic SQL:
```sql
DECLARE @SortColumn NVARCHAR(100)
SET @SortColumn = 'YourColumnName' -- Pass the column name as a parameter
DECLARE @SQLQuery NVARCHAR(MAX)
SET @SQLQuery = 'SELECT * FROM YourTable ORDER BY ' + QUOTENAME(@SortColumn)
EXEC sp_executesql @SQLQuery
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the concept of optimization?
What are user-defined functions (udfs) in sql server?
how do we insert 100 records at a time in a table without using for loop in database
What is a user-defined function in the sql server and what is its advantage?
You notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it?
In which year relase the 7.0& 2000 & 2005?
What are various ways to enhance the ssrs report?
What is global temp table?
What is difference between index and primary key?
Syntax to find the used space and free space of the Data file in a database(SQL Server). Following queries didn't give the exact Used space and Free Space Information sp_spaceused;DBCC showfilestats;exec MyDbName.dbo.sp_spaceused;SP_HELPFILE Can any one tell me the query for how to find the exact used data file space and free space in a Data File?
What do you understand by the analysis services in sql server?
Do you know what is replace and stuff function in sql server?
Oracle (3253)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)