SQL Server Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 225 Page Views: 

Having the following table:- sno val1 1 7.5 2 8 3 9.5 4 11 . . . N val Write the code to update the table where the difference in the column "val1" is computed i.e. (val1[2]-val1[1



Posted By: Avi Date: 1 October 2010 11:16:07 AM
 Answer:

Code Required is:- update cal set diff_val = 0 where ID = (select min(sno) from cal) Update cal set cal.diff_val = cal2.val - cal.val from cal inner join cal as [cal2] on [cal2].ID-1 = cal.ID


Posted By: avibtech


Date: 1 October 2010 11:16:07 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image gV9Zg5
Related Questions
SQL Server : Differentiate between IN and EXISTS operator in SQL Server?

Differentiate between IN and EXISTS operator in SQL Server?

IN:- The IN operator tells the rule-based optimizer to run the inner query first and then drive the ....
Category: SQL Server Date: 10/1/2010 11:56:08 AM
SQL Server : How many types of backups are available in SQL Server?

How many types of backups are available in SQL Server?

The scope of data backup can be whole data, partial ,or some files. On this basis of scope the follo....
Category: SQL Server Date: 10/1/2010 11:55:07 AM
SQL Server : While generating a realtionship between two tables why is it recommended to use CASCADE constraint?

While generating a realtionship between two tables why is it recommended to use CASCADE constraint?

Cascade constraint is used to maintain the consistency of the data. It automatically deletes the row....
Category: SQL Server Date: 10/1/2010 11:54:07 AM
SQL Server : Write a query to join 3 tables naming stud,result,Address. Inner join is to be applied on stud and result table and left outer join on the stud and address table. Also the condition given is where stud.roll is equal to 100.

Write a query to join 3 tables naming stud,result,Address. Inner join is to be applied on stud and r....

select * from stud s1 inner join result r1 on s1.key = r1.key left outer join address a1 on s1.key....
Category: SQL Server Date: 10/1/2010 11:53:07 AM
SQL Server : What is the purpose of bcp utility?

What is the purpose of bcp utility?

bcp utility copies bulk data between an instance of SQL server database and user defined file format....
Category: SQL Server Date: 10/1/2010 11:52:07 AM