SELECT Name.PersonName,Person.Age FROM Name, (Select PersonName,SUBSTRING(personName, 0, CHARINDEX(' ', personName)) AS toMatch FROM Name) as otherOne
WHERE
SUBSTRING(Name.PersonName, 0, CHARINDEX(' ', PersonName)) = otherOne.toMatch
and Name.PersonName <> otherOne.PersonName
Please Mark As Answer if it helped.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
Herewith I used Northwnd database, i trigger same with contactname .
try this code it will work fine.
SELECT [Customers].ContactName,[Customers].[City] FROM [Customers], (Select ContactName,SUBSTRING(ContactName, 0, CHARINDEX(' ', ContactName)) AS toMatch
FROM [Customers]) as otherOne
WHERE
SUBSTRING([Customers].ContactName, 0, CHARINDEX(' ', [Customers].ContactName)) = otherOne.toMatch
and [Customers].ContactName <> otherOne.ContactName
Mark as Answer if its help.
This will give you all records that have first name as Nikunj
Select * from tablaName where PersonName like 'Nikunj %'
I am running following code but it is giving me error.
Please help..
var query = "Select * from ShellModule where OriginalTable like =@0";
var file = "admin";
foreach(var a in db.Query(query, file+ " %")){ //showing error in this line of code
@a.IP<br/>
}
var query = "Select * from ShellModule where OriginalTable like @0";
var file = "admin";
foreach(var a in db.Query(query, file + " %")){ //showing error in this line of code
@a.IP<br/>
}
nikunj25
Member
288 Points
160 Posts
Reterving data from database??
Jul 05, 2011 11:24 AM|LINK
Hi,
I have a table called "Name". It has two colums "PersonName" and "Age".
I insert some data in it like that most of rows of "PersonName" has same first name buy different second name.
Now i want to print all the Person name with their age from database whose firstnames are same.
But problem is that both firstname and last name are in same colunm.
Can anybody tell me how i can do that.
And please don't suggest that make another column for last name.
Please help me......
bhupalb
Participant
777 Points
160 Posts
Re: Reterving data from database??
Jul 05, 2011 11:34 AM|LINK
hi
can u post the table data then we can try to give solution
i.e sample recordsfrom table name
B Bhupal
Lateef045
Star
7813 Points
1541 Posts
Re: Reterving data from database??
Jul 05, 2011 11:38 AM|LINK
This will give you all records that have first name as Nikunj
adeelehsan
All-Star
18297 Points
2740 Posts
Re: Reterving data from database??
Jul 05, 2011 11:51 AM|LINK
Hi
Use the following :
SELECT Name.PersonName,Person.Age FROM Name, (Select PersonName,SUBSTRING(personName, 0, CHARINDEX(' ', personName)) AS toMatch FROM Name) as otherOne WHERE SUBSTRING(Name.PersonName, 0, CHARINDEX(' ', PersonName)) = otherOne.toMatch and Name.PersonName <> otherOne.PersonNameMCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
Ravi_D
Participant
1212 Points
270 Posts
Re: Reterving data from database??
Jul 05, 2011 11:59 AM|LINK
Hi,
Herewith I used Northwnd database, i trigger same with contactname .
try this code it will work fine.
SELECT [Customers].ContactName,[Customers].[City] FROM [Customers], (Select ContactName,SUBSTRING(ContactName, 0, CHARINDEX(' ', ContactName)) AS toMatch FROM [Customers]) as otherOne WHERE SUBSTRING([Customers].ContactName, 0, CHARINDEX(' ', [Customers].ContactName)) = otherOne.toMatch and [Customers].ContactName <> otherOne.ContactName Mark as Answer if its help.D.Ravi
nikunj25
Member
288 Points
160 Posts
Re: Reterving data from database??
Jul 05, 2011 12:28 PM|LINK
I am running following code but it is giving me error.
Please help..
var query = "Select * from ShellModule where OriginalTable like =@0"; var file = "admin"; foreach(var a in db.Query(query, file+ " %")){ //showing error in this line of code @a.IP<br/> }chohmann
Star
9385 Points
1644 Posts
Re: Reterving data from database??
Jul 05, 2011 09:17 PM|LINK
var query = "Select * from ShellModule where OriginalTable like @0"; var file = "admin"; foreach(var a in db.Query(query, file + " %")){ //showing error in this line of code @a.IP<br/> }