All Tips & Questions

Tip of the day

SQL Server : 3 Tricky SQL Queries Interview Questions and Answers

1). SELECT 16    what is the output of this query?

A). Throw error
B). 16
C). 0
D). 1


2).SELECT $     what is the output of this query?

A). Throw error
B). $
C). 1
D). 0.00


3). SELECT COUNT(*)     what is the output of this query?

A). Throw error
B). 0
C). 1
D). *

- by Venkateswarlu Cherukuru

Question of the day

SQL Server : How to concatenate multiple rows into a single text string ?

Let us have a table with the following data:

CourseID    CourseName
1                 .Net
2                 SQL Server
3                 SSRS
4                 SharePoint
5                 WCF

We need to concatenate the ClientName column like the following:

.Net, SQL Server, SSRS, SharePoint, WCF

Solution - Method 1

SELECT CourseName + ', '
From CoursesTable
For XML PATH('')


Solution - Method 2

DECLARE @CourseNames VARCHAR(MAX);
SET @CourseNames = '';

SELECT @CourseNames = @CourseNames + IsNull(CourseName + ', ', '')
FROM CoursesTable
Select @CourseNames

- by Venkateswarlu Cherukuru


We are inviting Tips & Questions from you. Click Here to share your valuable Tips & Questions on this website.

  • Your Tips & Questions will be displayed on website, after validating the information you provided.
  • Tips & Questions will be refreshed on every day 12:00 AM IST.