.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> Sql Server >> Post New Question Subscribe to Interview Questions

HOW TO ASSIGN VALUE TO PARAMETERS USED IN QUERY WHICH IS STORED IN A VARIABLE?

Posted By :shankey     Posted Date :January 30, 2011    Points :15   Category :Sql Server 
Have a look at the following sql block

DECLARE
/* @STRQUERY AND @PARAMDEF SHOULD BE NVARCHAR
BECAUSE "EXECUTE sp_executesql" ACCEPTS STATEMENT AND PARAMETER OF TYPE 'ntext/nchar/nvarchar' ONLY
OTHERWISE
"Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'."
OR
"Procedure expects parameter '@parameters' of type 'ntext/nchar/nvarchar'." WILL BE RAISED*/
@STRQUERY AS NVARCHAR(200),
@STRNAME AS VARCHAR(100),
@PARAMDEF AS NVARCHAR(100),
@STRNAMEVALUE AS VARCHAR(100)
BEGIN
--FOLLOWING STATEMENT ASSING VALUE
SET @STRNAMEVALUE='MANINDER'
--FOLLOWING VARIABLE CONTAINS A QUERY WHICH USES A PARAMETER
SET @STRQUERY = 'SELECT ''YOUR NAME IS '' + @STRNAME'

--FOLLOWING STATEMENT DEFINES THE PARAMETERS USED IN THE QUERY
SET @PARAMDEF = '@STRNAME AS VARCHAR(100)'

--IN THE FOLLOWING STATEMENT "@STRNAME = @STRNAMEVALUE" STATEMENT ASSIGNS VALUE TO THE PARAMETER
--SYNTAX IS EXECUTE sp_executesql @STATEMENT, @PARAMETERS
EXECUTE sp_executesql @STRQUERY, @PARAMDEF,@STRNAME = @STRNAMEVALUE;
END

You can also find related Interview Question to HOW TO ASSIGN VALUE TO PARAMETERS USED IN QUERY WHICH IS STORED IN A VARIABLE?  below: 

can we assign Null value to Struct variable.

  
No , We cannot assign null to a struct variable, since structs are value type. (More...)

Which keyword is used to accept variable number of parameters?

  


Params keyword is used to accept variable number of parameters.

(More...)

Where are shared assemblies stored in .NET?

  
Shared Assemblies are stored in Global Assembly Cache also known as GAC. (More...)

What is the difference between ref & out parameters?

  
An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter. (More...)

What is a Stored Procedure?

  
Its nothing but a set of T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. (More...)

What is Query evaluation engine?

  
It executes low-level instruction generated by compiler. (More...)

Where are the ASP.NET configuration files stored?

  
System-wide configuration settings and some ASP.NET schema settings are stored in a file named Machine.config, which is located in the

%SystemRoot%\Microsoft .NET\Framework\versionNumber\CONFIG directory.

This directory also contains other default settings for ASP.NET Web applications in a file that is referred to as the root Web.config file. ASP.NET configuration files for individual Web sites and applications, which are also named Web.config files, can be stored in any Web site root directory, application root directory, application subdirectory, or all of these. For more information, see ASP.NET Configuration File Hierarchy. (More...)

Where is version information stored of an assembly ?

  
Version information is stored in assembly in manifest. (More...)

Where is image data loaded into ImageList controls actually stored in the project?

  
Each form has an associated resource file (with a .resx extension) where image data and localized strings are stored.You can see this by clicking the Show All Files icon in the Solution Explorer. (More...)

What are the differences among batches, stored procedures, and triggers?

  

Batch:
------
A batch is a group of one or more SQL statements. SQL Server compiles the statements of a batch into a single executable unit, called an execution plan. The statements in the execution plan are then executed one at a time.

stored procedure :
------------------
A stored procedure is a group of SQL statements that is compiled one time and can then be executed many times.

trigger:
--------
A trigger is a special type of stored procedure that is not called directly. Trigger is fired each time row is affected by Insert, Update or Delete command.


(More...)

How to remove a Session variable?

  
using HttpSessionState.Remove(); (More...)

What is Query binding ?

  
The binding of an object to a query (More...)

Maximum Data that can be stored in a cookie?

  
Maximum 4 KB data can be store in a cookie. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend