SQL Server

Comma-Delimited Output (SQL Server)

Using Query 1: USE Northwind 2: GO 3:  4: DECLARE @CustIDs VARCHAR(8000) 5: SELECT TOP 10 @CustIDs = ISNULL(@CustIDs + ‘,’, ”) + CustomerID FROM Customers 6: SELECT @CustIDs 7: GO   Using Cursor 1: DECLARE cCustomerIDs CURSOR FOR 2: SELECT [CustomerID] FROM [dbo].[Customers] ORDER BY [CustomerID] 3: DECLARE @CustomerIDs VARCHAR(8000) 4: DECLARE @CustomerID VARCHAR(10) [...]

Find the balance amount (sum(credit) – sum(debit)) from the following table?

Ans: find out the balance amount of account no: 1 1: SELECT a.SumCr AS Credit, 2: b.SumDr AS Debit, 3: a.SumCr – b.SumDr AS Balance FROM 4: (SELECT SUM(A_Amount) AS SumCr FROM tblAccount 5: WHERE A_ID = 1 AND A_Type = ‘Cr’) a, 6: (SELECT SUM(A_Amount) AS SumDr FROM tblAccount 7: WHERE A_ID = 1 [...]

Find out the N’th maxium salary?

Ans: find the 5th maxium salary: 1: SELECT TOP 1 * FROM tblEmployee WHERE E_Salary NOT IN 2: (SELECT DISTINCT TOP 4 E_Salary FROM tblEmployee ORDER BY E_Salary DESC) 3: ORDER BY E_Salary DESC