Dynamic sql table name variable

Dynamic sql table name variable

kudvenkat

7 лет назад

88,578 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Mehmet Kuzu
Mehmet Kuzu - 08.04.2023 14:43

Sir, how do we get back inserted value Id in a query where i use dynamic table name

Ответить
yogita chauhan
yogita chauhan - 02.09.2022 22:05

Sir, I have 25 to 30 tables, that I wanted to create dynamically using SP, can you guide me on how can I achieve that?

for example I have 4 tables
1 claim
2 claimEditor
3 claimmapc
4cliam encounter etc...
.
.
.
25

Now on executing SP if I pass 1 in parameter
My table should create as
1 claim_1
2 claimEditor_1
3 claimmapc_1
4cliam encounter _1 and so on

if I pass 2 in param
My table should be created as
1 claim_2
2 claimEditor_2
3 claimmapc_2
4cliam encounter_2
etc

Ответить
Wei Xiong
Wei Xiong - 28.01.2022 03:05

alter procedure spTableLookup
@tableName nvarchar(30)
as
begin
declare @lookuptable nvarchar(100)
set @lookuptable =N'select * from ' + QUOTENAME(@tableName)
execute sp_executesql @lookuptable
end

execute spTableLookup Employees;drop database SalesDB

Ответить
Drunkard Farnham
Drunkard Farnham - 07.01.2022 06:37

Thanks for the refresher

Ответить
Amal Ibrahim
Amal Ibrahim - 29.05.2020 18:45

You are the BEST!

Ответить
JMB ONIELS
JMB ONIELS - 13.04.2020 00:54

Great handout. Thanks with Easter blessings this day in Christ

Ответить
waqas riaz
waqas riaz - 24.05.2019 14:01

You are a champion !!
Very well explained lectures.

Ответить
Projjwal Maiti
Projjwal Maiti - 05.05.2019 20:38

what if we inject by
'Countries]; Drop Databse [SalesDb'

Ответить
Dongfan zhang
Dongfan zhang - 12.06.2018 15:01

Dear Vankat, how to pass two parameters, one as column name and other as the content of the column?
I tried to make a sp, does not seem to work as intended? Can you please give some advice? Thanks a lot

the query I want to achieve will be something like " Select * from customers where CustomerID = 'ALFKI'
so CustomerID and ALFKI will be the parameter @field and @search which are users inputs.

Create PROCEDURE [dbo].[getByColumnAndContentSearch]
@field nVarchar(50),
@search nVarchar(50)

AS
BEGIN
DECLARE @sql NVARCHAR(MAX);

SET @SQL = 'select * from customers where ' + QuoteName(@field)+' = '+QuoteName(@search)


EXEC(@sql)

END;

Ответить
jasmin s
jasmin s - 27.03.2018 11:51

What is the previous video of this video sir
Please send that link

Ответить
Purusotam
Purusotam - 29.01.2018 16:36

sir how to upload excel data with dynamic column name in database.Please respond its urgent...

Ответить
Frédéric Fantin
Frédéric Fantin - 16.10.2017 11:49

How to variabilize dynamically the table name of a 57k SQL statement ? As we can't build a stored procedure with a table name as a variable, and as a nvarchar(max) viariable can't contains more than 8k SQL statement! It seems that there is no solution with SQL server ?

Ответить
zu sdd
zu sdd - 23.04.2017 19:39

kudvenkat. plz keep going !

Ответить
RAVIKUMAR HAJARE
RAVIKUMAR HAJARE - 21.04.2017 19:16

please start xamrin tutorial

Ответить
Mohamad Helaly
Mohamad Helaly - 21.04.2017 08:19

thanx again and again. you are awesome

Ответить
Rehan Shaikh
Rehan Shaikh - 21.04.2017 08:18

Sir can you please tell us how to pass table name dynamically to function?

Ответить
Yogeshwar Goswami
Yogeshwar Goswami - 21.04.2017 06:18

please upload ssrs videos

Ответить
John Windsor
John Windsor - 21.04.2017 03:45

Very very nice video tutorial. I respect you so much!

Ответить
Muhammad Rehbar Sheikh
Muhammad Rehbar Sheikh - 21.04.2017 01:16

thank you venkat sir.. great explanation.. ALLAH bless you !

Ответить