Problem: I'm filling asp.net report from sql server by applying multiple joins on different tables. It works but creates a problem where am picking PoliceStation name by help of cell no. Problem is that 1 cell no can be of many police stations, so it picks each Policestation name and disply that it in report. I just want 1 police station name which i require from PoliceStations table
Query:
SELECT [ID]
,LEFT(REPLACE(convert(varchar, CmsSMSDb.dbo.SendMessages.SendingDateTime, 113), ' ','/'), 11) + ' ' +
RIGHT(REPLACE(convert(varchar, CmsSMSDb.dbo.SendMessages.SendingDateTime, 113), ' ','/'), 12)
as SendingDateTime
,[ToMobileNo]
,[Message]
,Designations.Name as [ToDesignation]
FROM [CmsSMSDb].[dbo].[SendMessages]
inner join
CPOCMS.dbo.Designations
ON CPOCMS.dbo.Designations.MobileNo = CmsSMSDb.dbo.SendMessages.ToMobileNo
where Convert(date,CmsSMSDb.dbo.SendMessages.SendingDateTime)>= @DateFrom
AND
Convert(date,CmsSMSDb.dbo.SendMessages.SendingDateTime)<= @DateTo
Union All
SELECT [ID]
,LEFT(REPLACE(convert(varchar, CmsSMSDb.dbo.SendMessages.SendingDateTime, 113), ' ','/'), 11) + ' ' +
RIGHT(REPLACE(convert(varchar, CmsSMSDb.dbo.SendMessages.SendingDateTime, 113), ' ','/'), 12)
as SendingDateTime
,[ToMobileNo]
,[Message]
,'SDpo'+' '+CPOCMS.dbo.PoliceStations.PsName as [ToDesignation]
From [CmsSMSDb].[dbo].[SendMessages]
inner join CPOCMS.dbo.PoliceStations
ON CPOCMS.dbo.PoliceStations.sDpo_ContactNo = SendMessages.ToMobileNo
where Convert(date,CmsSMSDb.dbo.SendMessages.SendingDateTime)>= @DateFrom
AND
Convert(date,CmsSMSDb.dbo.SendMessages.SendingDateTime)<= @DateTo
order by SendMessages.ID
e.g.
City Police St. | 0900800800
Bill Rd PoliceSt | 0900800800
i amy just want to send to one .