0

I have four tables:

  • dbo.Projects (id, ProjectName, Areas, PaymentSystem, Districts.id, purpose.id, types.id, etc)
  • dbo.Districts(id, DistrictsName)
  • dbo.Purpose (id, PurposeName) - has residential & commercial
  • dbo.Types (id, typName)

I want to select projects where DistrictsName='District1' and PurposeName = 'residential'

I tried this procedure :

alter PROCEDURE GetProjects
    @districtName nvarchar(50),
    @purposeName nvarchar(50)
as
    SELECT 
        p.ID, p.ProjectName,  p.Areas, 
        p.PaymentSystem, p.ReceivedDate,    
        p.PropertyClassification, 
        p.ProjectImage,         
        dis.DistrictName,
        Pur.PurposeName            
    FROM 
        dbo.Projects AS p 
    LEFT JOIN 
        dbo.Districts dis ON p.DistrictID = dis.ID   
    LEFT JOIN  
        dbo.Purpose pur ON p.PurposeID = pur.ID 
    WHERE 
       (dis.DistrictName = @districtName) 
       AND (Pur.PurposeName = @purposeName)

exec GetProjects @districtName='District1', @purposeName='residential '

When I execute this procedure, it returns with null - no data is returned.

Note: database supported Arabic language

When I execute this query it returns the result I think no data returned because Arabic language

SELECT 
    p.ID, p.ProjectName, p.Areas, 
    p.PaymentSystem, p.ReceivedDate,    
    p.PropertyClassification, 
    p.ProjectImage,         
    dis.DistrictName,
    Pur.PurposeName            
    FROM 
        dbo.Projects AS p 
    LEFT JOIN 
        dbo.Districts dis ON p.DistrictID = dis.ID   
    LEFT JOIN  
        dbo.Purpose pur ON p.PurposeID = pur.ID 
    WHERE 
        (dis.DistrictName = N'arabic value') 
        AND (Pur.PurposeName = N'arabic value')
8
  • 1
    How about remove the last blank character in purposename? ...,@purposeName='residential' Commented Dec 20, 2016 at 13:58
  • 1
    And you might as well change the two LEFT JOIN to INNER JOIN. The WHERE clause turn them to INNER JOIN any way. Commented Dec 20, 2016 at 14:00
  • still no data return when i remove ...,@purposeName='residential' Commented Dec 20, 2016 at 14:04
  • Do you have any data where the districtname = 'District1'? I don't see anything wrong with your query so it must be data. Commented Dec 20, 2016 at 14:05
  • 1
    Then run your stored procedure with this: exec GetProjects @districtName=N'arabic value',@purposeName=N'arabic value' and see if you get result? The problem might be in the Unicode things. Commented Dec 20, 2016 at 14:19

1 Answer 1

1

Use this execution command

exec GetProjects @districtName=N'arabic value',@purposeName=N'arabic    value'

Put the N in front to indicate you are using Unicode.

Sign up to request clarification or add additional context in comments.

2 Comments

this command return the result i want but i want to remove this static value and make it parameter
Keep the stored procedure "as is" (as in as before you posted the question). Then run it using the parameter @districName=N'<<your value here>>>', @purposeName=N'<<<your value here>>>'. If it does not return value, you do not have value for that parameter. Simple as that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.