Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CREATE PROCEDURE CustomerListByState @States VARCHAR(128) AS BEGIN DECLARE @SQL NVARCHAR(1024) SET @SQL = 'select CustomerID, CompanyName, ContactName, Phone, Region from Customers where Region IN ('

CREATE PROCEDURE CustomerListByState @States VARCHAR(128)

AS

BEGIN

DECLARE @SQL NVARCHAR(1024)

SET @SQL = 'select CustomerID, CompanyName, ContactName, Phone, Region from Customers where Region IN (' + @States + ')' + ' order by Region'

PRINT @SQL -- For testing and debugging /* The following query is executed as dynamic SQL select CustomerID, CompanyName, ContactName, Phone, Region from Customers where Region IN ('WA', 'OR', 'ID', 'CA') order by Region */ -- Dynamic SQL execution

EXEC Sp_executesql @SQL

END

GO

-- Execute dynamic SQL stored procedure

DECLARE @States VARCHAR(100)

SET @States = '''WA'', ''OR'', ''ID'', ''CA'''

EXEC CustomerListByState @States

GO

(1) What kind of dynamic SQL it is? (such as passing input / output parameters or concatenating the user inputs, etc.)

(2) Explain the problem?

(3) Is this dynamic sql efficient or not? Why?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago