C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

11 common T-SQL


Posted Date: 12 Dec 2005    Resource Type: Articles    Category: .NET Framework
Author: DotNET-HelperMember Level: Gold    
Rating: 1 out of 5Points: 7




1. To find the total number of rows in a Table


select rows from sysindexes where id=object_id('employees') and indid <2



2. Select the details of 3 max salaried employees from employee table.

	

SELECT TOP 3 empid, salary FROM employee ORDER BY salary DESC



3.Display all managers from the table. (manager id is same as emp id)


SELECT empname FROM employee WHERE (empid IN (SELECT DISTINCT mgrid FROM employee))

4. Write a Select statement to list the Employee Name, Manager Name under a particular manager?

SELECT e1.empname AS EmpName, e2.empname AS ManagerName
FROM Employee e1 INNER JOIN
Employee e2 ON e1.mgrid = e2.empid
ORDER BY e2.mgrid

5. How to know how many tables contains empno as a column in a database?

SELECT COUNT(*) AS Counter FROM syscolumns WHERE (name = 'empno')

6.How to delete the rows which are duplicate - yourtable(name1,age1) (don’t delete both duplicate records).

SET ROWCOUNT 1
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = a.name1 AND b.age1 = a.age1) > 1
WHILE @@rowcount > 0
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = a.name1 AND b.age1 = a.age1) > 1
SET ROWCOUNT 0

7.How to find 6th highest salary

SELECT TOP 1 salary
FROM (SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary


8.Write a query to convert all the letters in a word to upper case

SELECT UPPER('test')

9. Write a SQL Query to find first day of month?

SELECT DATENAME(dw, DATEADD(dd, - DATEPART(dd, GETDATE()) + 1, GETDATE())) AS FirstDay

10. Write a query to round up the values of a number. For example even if the user enters 7.1 it should be rounded up to 8.

SELECT CEILING (7.1)

11.How to list all the tables in a particular database?

sp_help











Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Cryptography in .NET
Previous Resource: Digimaker released Developer's Kit - Featured CMS with One free license
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use