Search
 
SCRIPT & CODE EXAMPLE
 

SQL

how to pass dynamic column name in sql query

DECLARE @sqlCommand varchar(1000)
DECLARE @columnList varchar(75)
DECLARE @city varchar(75)

SET @columnList = 'AddressID, AddressLine1, City'
SET @city = '''London'''
SET @sqlCommand = 'SELECT ' + @columnList + ' FROM Person.Address WHERE City = ' + @city

EXEC (@sqlCommand)
Comment

PREVIOUS NEXT
Code Example
Sql :: install mysql 5.7 ubuntu 20.04 
Sql :: sql trim from string 
Sql :: psql generate id in existing database 
Sql :: sql column name 
Sql :: how to get connect string from mysql database 
Sql :: where condition in mongodb 
Sql :: Using GROUP BY in MySQL Join Table 
Sql :: oracle show parameter 
Sql :: sql server check whether column has same equal values 
Sql :: SQL Updating a View 
Sql :: pg_pretty_size 
Sql :: sql last time database was accessed 
Sql :: SQL SELECT DISTINCT Statement 
Sql :: Add colum sqlite table 
Sql :: error 1054 mysql 
Sql :: sub query postgres 
Sql :: Assign value to variable inside Dynamic SQL 
Sql :: SQL Remove Primary Key Constraint - MySQL 
Sql :: mysql command 
Sql :: sql select all tables from database change url 
Sql :: insert select 
Sql :: sql output select 
Sql :: forcefully delete a row in mysql which has references 
Sql :: power bi union columns 
Sql :: sql select most frequent value in group 
Sql :: how to relationship query two different tables in MySQL 
Sql :: display first three characters sql 
Sql :: sqlite update query python 
Sql :: mysql date_format 
Sql :: sql server delete records with specific date 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =