SQL Server tutorial for beginners - FIRST VALUE function in SQL Server

Database, Information Technology

SQL Server tutorial for beginners

593 Lessons

FIRST VALUE function in SQL Server

In this video we will discuss FIRST_VALUE function in SQL Server

FIRST_VALUE function
Introduced in SQL Server 2012
Retrieves the first value from the specified column
ORDER BY clause is required
PARTITION BY clause is optional

Syntax : FIRST_VALUE(Column_Name) OVER (ORDER BY Col1, Col2, …)

FIRST_VALUE function example WITHOUT partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the entire table.

SELECT Name, Gender, Salary,
FIRST_VALUE(Name) OVER (ORDER BY Salary) AS FirstValue
FROM Employees

FIRST_VALUE function example WITH partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the respective partition.

SELECT Name, Gender, Salary,
FROM Employees

Text version of the video


All SQL Server Text Articles

All SQL Server Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

    1NF 2005 2008 2012 2NF access temp table created in dynamic sql ACID Tests add check constraint to existing column add default constraint to existing column in sql server add foreign key to existing table in sql server add new column with default constraint add unique column to table sql server adhoc sql advanced joins Advantages after delete After insert after triggers after() all tables Alter alter stored procedure sql server alter table add check constraint sql server alter table add default constraint to existing column sql server alter table add foreign key constraint sql server alter table add foreign key sql server alter table check constraint alter table check constraint sql server altering alternatives analyze deadlock graph sql server Arguments ASCII asp.net build dynamic sql query asp.net c# search page asp.net dynamic sql query asp.net sql server deadlock assign output sp_executesql variable before delete trigger example before delete trigger in sql server before insert update delete trigger before update trigger in sql before update trigger in sql server before update trigger in sql server 2008 r2 before update trigger mssql before update trigger sql server 2005 before update trigger vs after update benefits Better between built-in c# call sp_executesql c# create dynamic sql query c# execute sp_executesql calculate exact age in sql server can database views be updated can sql view be updated cannot drop database because it is currently in use Cascading case statement cast catch deadlock exception c# char CHARINDEX check constraint check empty guid in sql server check guid is null or empty sql server check if table exists sql choose function in sql 2012 Clustered clustered index explained clustered index in dbms clustered index order clustered index primary key clustered vs. nonclustered index structures in sql server Coalesce function coalesce in sql server 2008 coalesce sql problem coalesce() example column default columns common table expression common table expressions compare uniqueidentifier null concurrency problems database concurrency problems lost update constraints convert convert rows to columns sql correlated correlated subquery how it works correlated subquery in dbms correlated subquery tutorial correlated subquery vs non correlated subquery correlated subquery vs subquery correlated subquery working covering queries crear trigger sql server create create before delete trigger sql server create before insert trigger in sql server create dynamic temp table in sql server create function with schemabinding example create global temporary table create sequence in sql server create sql view with parameters create table referential integrity sql create temp table dynamic sql create trigger on all server for ddl events create unique column in sql server Creating Creating Tables cross apply sql server example cross apply sys.dm_exec_query_plan(plan_handle) cross apply sys.dm_exec_sql_text cross join cross self join cte cte insert update delete cte reference itself cte update and insert cte update join cte vs table variable cte vs temp table vs table variable cube group by sql cumulative total in ms sql server cursors database database acid examples database acid properties database acid properties with example database concurrency lost update database design normalization database index basics database index best practices database index creation database index example database index guidelines database index how it works database index performance database index simple explanation database index speed up query performance database index techniques database index tutorial database index when to use database locks database normalization database normalization 1nf database normalization 2nd normal form database normalization 3nf database normalization example database normalization made easy database normalization normal form database normalization process database normalization questions and answers database normalization tutorial for beginners database systems normalization database transaction lost update date Date Time datefromparts in sql server DateName datetime datetime vs datetime2 sql server datetime vs smalldatetime sql server DateTime2FromParts datetimefromparts sql 2012 day DBCC CHECKIDENT dbcc opentran example dbms dbms 3nf dbms acid properties dbms deadlock dbms normal forms tutorial dbms normalization dbms normalization with example ddl trigger example ddl trigger example in sql server ddl trigger on all server ddl trigger server level ddl triggers can be used to deadlock database deadlock example deadlock example in sql server 2005 deadlock example in sql server 2008 deadlock explanation deadlock graph analysis deadlock graph analyze deadlock graph sql server deadlock graph sql server 2008 deadlock in sql server 2008 with example deadlock questions deadlock retry logic deadlock tutorial debug in sql server management studio debugging in ssms debugging t-sql code default DEFAULT Constraint defined delete default constraint in sql server delete sql constraint delete sql stored procedure delete trigger before delete sql server dense_rank vs rank vs row_number sql server derived tables DETERMINISTIC difference difference between cube and rollup in sql server 2005 difference between cube and rollup in sql server 2008 difference between exec and sp_executesql in sql server difference between intersect and except in sql server difference between intersect and union difference between join and subquery in sql difference between not in and except in sql server difference between phantom read and non-repeatable read difference between rank and dense_rank with example difference between read committed snapshot and snapshot isolation level difference between repeatable read and serializable difference between rows clause and range clause in sql server difference between static and dynamic sql statements difference between static and dynamic stored procedure difference between stored procedure and dynamic sql difference between subquery and correlated subquery difference between union and join in sql server difference between union and union all different normal forms dirty read concurrency dirty read problem in concurrency control distinct DML trigger dml triggers drop drop check constraint sql server drop sql stored procedure drop unique clustered index drop unique constraint sql server drop unique index sql server dropping dynamic query in sql server with parameters dynamic sql example dynamic sql into temp table dynamic sql prevent sql injection dynamic sql return output parameter dynamic sql select from temp table dynamic sql sql server tutorial dynamic sql stored procedure with parameters dynamic sql temp table scope dynamic sql temp table stored procedure dynamic sql temp table variable Dynamic SQL vs Stored Procedure dynamic sql without sql injection dynamic sql youtube dynamic table name in from clause dynamic table name in query dynamic table name in select statement dynamic table name in sql query dynamic table name in sql stored procedure dynamic table name tsql dynamic temp table in sql server enable read committed snapshot isolation sql server encrypting a function in sql server enforcing error Error Handling example examples except vs not in sql server Exception Handling exec dynamic sql example exec function in sql exec in sql server.exec dynamic sql sql server exec sp_settriggerorder exec sql injection execute dynamic sql sql server execute procedure with in and out parameter executing existing table new column default constraint explain default constraint with example Filtering groups first normal first normal form first_value foreign key foreign key constraint in sql example foreign key example in sql server fractions FULL JOIN function functions functions in sql server get cached execution plan for stored procedure get execution plan for stored procedure sql server get execution plan from cache sql server get id of just inserted row get non matching rows in sql global variables Group By group by cube in sql server 2008 group by having sql server group by sql pivot group by with rollup example grouping grouping sets examples in sql server grouping_id function in sql server 2008 grouping_id in sql server 2008 example guid data type sql server guid pros and cons guid vs int primary key performance handle deadlock in asp.net handling sql server deadlock how can you get a deadlock graph from sql server how sql server detects deadlocks how to check if uniqueidentifier is null how to create before update trigger in sql server 2008 how to create guid in sql how to debug t sql how to execute dynamic sql in stored procedure how to find deadlock in sql server how to get month number from date in sql how to give dynamic table name in sql how to improve query performance using index how to log deadlocks in sql server how to output row count in sql stored procedure how to pass datatable to stored procedure in c#.net how to pass table name dynamically for stored procedure in sql server how to prevent sql injection attacks how to prevent sql injection attacks in asp.net how to prevent sql injection attacks in sql server how to search data in sql database using asp.net how to search data using stored procedure in asp.net c# how to use sql injection in stored procedure huge tables ident_current vs scope_identity ident_current vs scope_identity vs identity IDENT_CURRENT('TableName') identity Identity column identity column value IDENTITY_INSERT identity_insert in sql server iif function in sql server 2012 iif function in sql server example implement search in website asp.net c# improve sql query performance index in index and performance sql index performance sql server indexed views Indexes information_schema.tables Inline inline sql inline table valued function parameters inline table valued function with parameters INNER JOIN inner join vs cursor inner self join insert insert into select only some columns instead of instead of delete instead of insert trigger instead of insert update delete intelligent joins intersect vs except IsDate ISNULL function isnull uniqueidentifier in sql server 2008 Joining with the same table Joins Joins in SQL Server lag last_value function in sql server 2008 lead learn everything about sql learn sql at home learn sql for beginners learn sql programming learn sql queries learn sql step by step left LEFT JOIN left join and null values left join case null left join null check left join null coalesce left join null values left join null values sql server left outer join in sql left outer join replace null values LEN like list lost update problem in concurrency control lost update problem in transaction lower ltrim materialized view explained materialized view in dbms materialized view in sql materialized view join materialized view simple example materialized view tutorial materialized view vs view materialized view youtube Materialized Views mathematical merge in sql merge in sql server merge in sql server 2008 merge in sql server 2008 example merge in sql server example merge statement in sql server merge two tables sql union modification affects multiple base tables modify data using view sql server modify stored procedure in sql server month ms sql dynamic temp table ms sql get age from date of birth ms sql pivot ms sql server 2012 eomonth ms sql server eomonth ms sql server object dependencies mssql mssql offset fetch multi non clustered non repeatable read in dbms non repeatable read in sql non repeatable read sql server Nondeterministic ntile only non matching rows Operator Optional order by outer join outer self join output parameters over partition by clause in sql over partition by in sql server 2008 Parameters Partition partition by clause in sql server 2008 pass datatable to stored procedure in sql server 2008 pass table variable as parameter to stored procedure pass table variable to sql stored procedure performance performance stored procedure vs query performance testing phantom read and non repeatable read phantom read database phantom read in dbms phantom read problem in database phantom read problem in dbms phantom read problem in transaction phantom read vs non repeatable read phantom reads in sql server 2008 phantom rows in sql server pivot pivot and unpivot examples in sql server pivot and unpivot table sql server pivot example in sql server 2014 precision prevent saving changes sql server management studio prevent saving changes that require the table to be recreated sql prevent sql injection c# prevent sql injection in dynamic query primary key primary key column in sql server primary key enforcement primary key foreign key example in sql server primary vs unique key sql proc proc sql count output procedure Procedure expects parameter '@params' of type 'ntext/nchar/nvarchar' procedures pros and cons pros and cons of stored procedures purpose Queries query quotename dynamic sql quotename example in sql server quotename example in sql server 2008 quotename in sql server 2008 with example quotename sql example quotename sql injection quotename tsql quotename variable quotename where clause random data range between unbounded preceding and current row range between unbounded preceding and unbounded following range clause vs rows clause in sql server range vs rows in sql server rank and dense_rank example rank dense_rank row_number in sql server rank vs dense_rank in sql server 2008 rdbms acid properties re-runnable Read and analyze sql server deadlock log Read committed snapshot isolation level in sql server 2008 read committed snapshot vs snapshot isolation level read sql server deadlock log Recreate recursive cte recursive cte ordering hierarchical result recursive cte with level referential integrity constraint referential integrity constraint in database referential integrity constraint in dbms with example referential integrity constraint in relational database referential integrity example referential integrity in database with example referential integrity sql server relational database self join repeatable read isolation level repeatable read isolation level example replace NULL values Replacing cursors rerunnable reseed id column sql server reseed identity column sql server reset identity column sql server Reset identity value restrict column values in sql server Retrieve return values reverse Right RIGHT JOIN rollup and cube in sql server 2005 rollup function in sql server row_number vs rank vs dense_rank in sql server rows range clause rtrim running total column running total example in sql server running total sql server scalar scalar function in select statement Schema binding scope_identity vs @@identity example scope_identity vs @@identity in sql server scope_identity vs ident_current SCOPE_IDENTITY() scripts second normal form second normal form database second normal form examples second normal form in dbms second normal form with simple example select select distinct sql select into copy table structure select into existing table sql server select into from different server select into from external database select into from multiple tables select into from one server to another select into from two tables select into schema only select into temp table dynamic sql self join self join employee manager example self join find manager self join operation in dbms self join select query self join to get manager name self referencing table example self referencing table query send table variable to stored procedure Server single stored procedure for insert update and delete in sql server smalldatetimefromparts sql server snapshot isolation example snapshot isolation in dbms snapshot isolation level example snapshot isolation vs read committed snapshot Sorting sorting union query sp executesql capture output sp executesql prevent sql injection sp_executesql asp net sp_executesql dynamic sql sp_executesql dynamic sql output sp_executesql example in sql server sp_executesql input and output parameters sp_executesql multiple input parameters sp_executesql multiple parameters sp_executesql output count sp_executesql output into variable sp_executesql output parameter sp_executesql output row count sp_executesql output to variable sp_executesql parameters example sp_executesql parameters sql injection sp_executesql quotename sp_executesql system stored procedure sp_help stored procedure sp_helptext stored procedure sp_helptext stored procedure in sql server sp_readerrorlog sp_settriggerorder example sp_settriggerorder in sql server sql sql abs function example sql acid properties sql add unique constraint existing column sql age from dob sql alter table column sql alter view sql before delete trigger sql calculate power sql calculate square root sql cannot insert duplicate key in object sql case check if null sql ceiling function example sql check if guid is empty sql check if guid is null sql check if string is valid date sql check if uniqueidentifier is empty sql check unique identifier is null sql clear cached query plans sql clustered vs nonclustered index sql coalesce firstname lastname sql coalesce keyword sql coalesce multiple columns sql coalesce operator sql coalesce string sql commit rollback sql complex join queries examples sql concatenate int and string sql concatenate int and varchar sql convert date dd/mm/yyyy sql convert date to dd/mm/yyyy sql convert date to nvarchar sql convert datetime to date sql convert int to string sql convert text to lowercase sql convert text to uppercase sql count characters in string sql covered query sql create column if not exists sql create custom function sql create database tutorial sql create function with encryption sql create table if not exists sql create table only if it doesn't exist sql create trigger sql create trigger after insert sql create view from query sql create view two tables sql cross join sql current_timestamp example sql cursor explained sql cursor inner join sql cursor processing sql cursor tutorial sql datediff birthday age sql datepart date only sql deadlock explained sql delete database sql delete empty space sql delete view sql developer left string sql developer right function sql dob to age sql drop and create table sql drop database sql dynamic query vs stored procedure sql dynamic table name in from sql eomonth example sql except example sql except operator example sql exec sp output parameter sql execute output example sql execute output variable sql execute stored procedure sql find index in database sql find pattern in string sql find square root sql floor function sql format date dd/mm/yyyy sql full join example sql full outer join sql full outer join null sql function calculate age sql function in select statement sql function in where clause sql function with encryption sql generate random number between 1 and 100 sql generate random number between range sql get data from two tables sql get day number from date sql get id of inserted row sql get id of last inserted row sql get month name from date sql getdate example sql getutcdate example sql getutcdate function sql group by and having sql group by and sum query sql group by cast date sql group by clause sql group by complex examples sql group by count sql group by date of datetime sql group by datetime sql group by examples sql group by explained sql group by function sql group by having example sql group by multiple aggregate functions sql group by multiple columns sql group by not working sql group by sum total sql group by with multiple columns sql group by youtube sql how to create a view sql if table exists drop and create sql ignore dup key sql index best practices sql information_schema tables sql inner join and outer join sql inner join example sql inner join tutorial sql insert data into temp table sql intersect vs join sql isnull function sql join subquery sql join vs union sql last inserted identity sql left function example sql left join and right join sql left join example sql left join null values sql left join tutorial sql logging deadlocks sql loop for each row in table sql loop through rows sql ltrim rtrim example sql mask characters sql mask phone number sql mask sensitive data sql merge two tables into one sql merge two tables with same columns sql missing index query sql non matching records two tables sql order by tutorial sql outer join null values sql output clause sql pivot interview questions sql pivot multiple aggregate functions sql pivot multiple columns example sql pivot tutorial sql power example sql power exponent sql procedure alter sql profiler deadlock detection sql profiler deadlock graph sql profiler trace deadlocks sql query and index sql query join vs subquery sql query to calculate age from date of birth sql query to reverse string sql quotename returns null sql rand function example sql referential constraint sql referential integrity constraint violation sql remove blank space at end sql remove empty spaces sql remove trailing blank spaces sql remove whitespace from start of string sql repeat string n times sql Right Join sql right join tutorial sql rollback example sql rollback transaction on error sql rollup example sql round to 2 decimal places sql round to nearest whole number sql rounding decimal places sql saving changes is not permitted sql saving changes is not permitted dropped and recreated sql script to generate test data sql select distinct statement sql select queries sql select statement tutorial sql server sql server 2000 sql server 2005 sql server 2005 deadlock try catch sql server 2008 sql server 2008 concurrency issues sql server 2008 ddl trigger audit sql server 2008 group by rollup sql server 2008 grouping sets example sql server 2008 rollup examples rollup clause in sql server sql server 2008 try catch deadlock sql server 2008 while loop insert sql server 2012 choose function sql server 2012 eomonth example sql server 2012 offset fetch next sql server 2012 paging stored procedure sql server alter database name sql server ascii character sql server before delete trigger example sql server before insert trigger change value sql server before update trigger change value sql server catch deadlock exception sql server change database name sql server choose function sql server concurrency issues sql server convert columns to rows in a table sql server crash course sql server create database sql server create database example sql server create empty guid sql server create guid sql server create table sql server create table with foreign key sql server create table with primary key sql server create temp table dynamically sql server cte in union sql server cte inner join sql server cube group by sql server database sql server deadlock analysis sql server deadlock code sql server deadlock detection sql server deadlock explained sql server deadlock explanation sql server deadlock graph xml how to read deadlock graph sql server deadlock log sql server deadlock log file sql server deadlock priority sql server deadlock priority example sql server deadlock retry logic sql server deadlock scenarios sql server deadlock script sql server deadlock update statement sql server deadlock victim sql server deadlock victim chosen sql server detect deadlock sql server difference between exec and sp_executesql sql server difference between rank and dense_rank sql server dirty read nolock sql server dynamic sql in stored procedure sql server dynamic sql output parameter sql server dynamic sql output variables sql server eomonth example sql server eomonth function sql server except clause sql server except example sql server except order by sql server exec output example sql server find blocking processes sql server flush execution plan sql server free training sql server from scratch sql server generate query plan sql server get execution plan for stored procedure sql server get id of last inserted row sql server group by cube example sql server group by rollup sql server group by union all sql server group by where having sql server grouping level sql server grouping sets order by grouping sql server identity vs sequence sql server iif function example sql server index impact on insert sql server information_schema sql server inner join sql server inner join remove duplicates sql server inner join table valued function sql server intersect example sql server intersect vs inner join sql server join table function with parameter sql server kill connections sql server kill query sql server kill spid sql server kill transaction sql server last_value function example sql server last_value function returns incorrect data sql server last_value function with partition example sql server left outer join null sql server level ddl trigger sql server list blocking processes sql server logon trigger audit sql server logon trigger example SQL Server Management Studio sql server management studio debug stored procedure sql server management studio object dependencies sql server missing index impact sql server missing index improvement measure sql server non schema bound dependency sql server non-repeatable read sql server object dependencies sql server object dependency tree sql server offset fetch example sql server outer apply example sql server outer join null sql server over clause partition sql server phantom read example sql server profiler deadlock analysis sql server profiler deadlock graphs sql server profiler dynamic sql sql server profiler exec sp_executesql sql server quotename dynamic sql sql server quotename single quote sql server random seed sql server read committed snapshot example sql server read uncommitted example sql server read uncommitted isolation level sql server referenced objects sql server referencing entities sql server remove cached execution plan sql server remove quotename sql server repeat spaces sql server retry after deadlock sql server retry on deadlock sql server rollup example sql server rollup grouping sql server rollup grouping replace null sql server rollup replace null sql server rollup vs cube sql server row number by partition sql server row_number example sql server row_number over partition by order by sql server running total query sql server schema bound dependency sql server search stored procedures for table sql server select deadlock victim sql server set identity_insert on sql server set trigger order sql server snapshot isolation level sql server sp depends stored procedure sql server table changes tracking sql server the text for object is encrypted sql server transpose columns to rows sql server trigger instead of vs after sql server trigger update another table sql server trigger update multiple columns sql server try_convert sql server tryparse sql server unique constraint column sql server uniqueidentifier advantages sql server uniqueidentifier default value sql server uniqueidentifier empty value sql server uniqueidentifier primary key auto generated sql server unpivot example sql server view update multiple tables sql server where vs having sql sort union results sql sorting sql square a number sql stored procedure dynamic where clause sql stored procedure encryption sql stored procedure parameter example sql stored procedure with parameters sql string length sql string replace example sql subqueries sql subquery and join sql subquery group by sql Subquery IN SELECT sql subquery join example sql subquery practice sql subquery returned more than 1 value error sql subquery tutorial sql subquery vs join sql subquery with aggregate function sql subquery with group by sql subquery with join sql subquery with multiple tables sql substring email domain sql substring query sql table name variable stored procedure sql trace flag 1222 sql training for beginners sql training for beginners youtube sql training online sql transaction commit rollback example sql trigger deleted table sql trigger example sql trigger example after insert sql trigger in dbms sql trigger insert update and delete sql trigger inserted sql trigger on insert sql trigger update column sql trigger update compare old new values sql trigger update example sql trigger update for each row sql trigger update old value sql triggers and stored procedures tutorial sql triggers for beginners sql turn identity_insert on sql udf case statement sql union all remove duplicates sql union not returning all rows sql union order of results sql union results of two queries sql unique constraint column sql unique constraint vs primary key sql unique key vs primary key sql uniqueidentifier null check sql update data using view sql update rollback commit sql update trigger sql update trigger inserted deleted sql update trigger loop sql update view multiple tables sql use temp table in view sql view aggregate functions sql view and order by sql view best practices sql view default constraints sql view default value sql view join multiple tables sql view join two tables sql view order by doesn't work sql view query sql view update data sql view update multiple tables sql view usage sql view vs select sql view vs table sql virtual table sql where clause multiple conditions sql where clause order sql where like and not like sql while loop example insert sql while loop insert into table sql wildcard operators sqlcode for deadlock sqlserver repeatable read ssms create database statement status return stored stored proc vs inline sql stored procedure stored procedure basics in sql server stored procedure create temp table example stored procedure dynamic sql injection stored procedure dynamic sql query stored procedure input parameter stored procedure insert update delete sql server stored procedure or query which is faster stored procedure reduce network traffic stored procedure security sql server stored procedure sql dynamic where clause stored procedure sql injection attack stored procedure temp table scope stored procedure vs dynamic sql advantages stored procedure vs dynamic sql performance stored procedure vs sql statement stored procedure with parameters in sql stored procedure youtube stored procedures String string functions sub query subqueries subquery subquery and correlated query SUBSTRING sys.dm_exec_cached_plans stored procedure sys.dm_sql_referenced_entities sys.tables sysobjects System t sql basics t sql before update trigger example t sql coalesce multiple columns t sql create empty guid t sql create new database t sql debug stored procedure t sql quotename single quote t-sql t-sql convert ascii code to char t-sql create database t-sql default constraint example t-sql dynamic query temp table t-sql fundamentals t-sql quotename examples t-sql scalar function in where clause table table check constraint table identity reset table level check constraint sql server table name as variable in sql table valued function join example table valued parameters example table variable and temp table difference table variable in sql table variable in sql server table variable vs temp table tables temp temp table best practices temp table inside dynamic sql temp tables in stored procedures temporary test data the lost update problem example third normal form 3nf example third normal form example third normal form in database with example time top n rows trace deadlocks in sql server 2008 trace sql server deadlock transaction acid properties in dbms transaction acid properties with example transaction concurrency problem transaction isolation level transaction isolation level sql server transactions transactions in sql server trigger in sql developer trigger insert sql server trigger sql developer trigger to update view trigger update another table triggers try catch blocks try catch deadlock sql server try catch deadlock sql server 2008 sql server try catch deadlock try convert function in sql try convert sql try parse int sql server try_convert in sql server 2012 try_parse in sql server 2012 try_parse vs try_convert sql server tsql tsql dynamic sql output parameter tsql generate random data undo pivot table sql server Union union 2 tables sql Union All union vs intersect sql server union vs union all union vs union all sql server unique column vs primary key unique constraint null sql server unique index unique key constraint uniqueidentifier in sql server unpivot in sql server example unrepeatable read problem updatable ctes Update update conflict snapshot isolation level update on cte update through cte update using cte update view based on multiple tables update view multiple base tables updateable views upper Use use dynamic table name in stored procedure user using quotename in sql valued values View limitations view or function is not updatable view vs table variable view vs temp table views violation of primary key constraint what happens if there is a deadlock where why stored procedure is better than inline query why we use dynamic sql wild cards window with with encryption without xtype Year