Getting column values as comma seperated list using XML PATH()



select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252




select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252


Getting column values as comma seperated list using XML PATH()



select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252




select tc.customerid,stuff((
select ',' + convert(nvarchar(30),tct.Customer_TripId)
from tollplus.TP_Customers tc
inner join tollplus.TP_Customer_Trips tct
on tc.customerid=tct.customerid and tc.customerid=60000252
for xml path('')),1,1,'')as usergroups
from tollplus.TP_Customers tc where tc.customerid=60000252


SqlServer - Ordering result set with null values after non-null values


Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

SqlServer - Ordering result set with null values after non-null values


Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Order by with null values in sql server is a tricky. Normally it puts the result set like: NULL, NULL, 1,2,3...etc

If your want the result set like: 1,2,3,NULL, NULL,......etc there is not direct method for this. You have to use the below script to get the required output.


declare @MaxId int
select @MaxId = max(code) + 1 FROM TableA

SELECT code
FROM TableA
ORDER by isnull(code, @MaxId)

Sql Server 2008 Installation Process

For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm
For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm

Sql Server 2008 Installation Process

For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm
For Sql server 2008 Installation Process.

Check the below URL to get the Clear Information.

http://www.sqlcoffee.com/SQLServer2008_0011.htm

Filter data by using IN and NOT IN clause

In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it
In this post I am going to show some SQLqueries and LINQ queries, but not going to show images for all cases.Filter data by using IN and NOT IN clause

Most of the developer who started working on LINQ queries gets confuse when they got requirement to write IN and NOT IN query using LINQ.


SQL Query
//IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

or

//NOT IN
SELECT [Id], [UserId], [IMEINo]
FROM [UserClients]
WHERE [UserId] IN (3, 4)

as you see above query use IN and NOT IN clause to filter from list of records.

LINQ Query
To achieve similar task LINQ make use of Contains function of C#. which do filtering of record form the list of record.

//IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where chosenOnes.Contains(u.UserId.Value)
select new { u.id,u.userid, u.ImeiNo};

or

//NOT IN
int[] chosenOnes = { 3, 4 };
var user = from u in UserClients
where !chosenOnes.Contains(u.UserId.Value)
select u;

Note :
IN and NOT IN use same function in LINQ query but it just use !(Not) symbol for it