Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

I am creating a simple SQl server Join command. The problem is that the field to join will have string also consisting of single quotes which is not working.

Also, how can I use 2 criteria for Join of 2 tables.
Here, the field bom.bommn is string which may contain single quotes or double quotes.


SQL
Select PBOMS,PBOMM,PBOMTAG,PBOMMT,PBOMQ as NewQty,PBOMU,BOM.BOMIQ AS StdQty
 FROM PBOM LEFT JOIN BOM ON (PBOM.PBOMM = BOM.BOMMN and PBOM.PBOMMT=BOM.BOMIN) where
 PBOMPC=@PBOMPC AND PBOMG=@PBOMG and PBOMETY<>@PBOMETY AND PBOMS LIKE @PBOMS
 AND PBOMM LIKE @PBOMM AND PBOMTAG LIKE @PBOMTAG
Posted
Comments
PIEBALDconsult 19-Nov-14 12:16pm    
"consisting of single quotes" -- Shouldn't be a problem, seeing as you're using parameters.

"how can I use 2 criteria for Join of 2 tables" -- What you show seems OK, what's wrong? Or do you want to JOIN to a table twice?
Maciej Los 19-Nov-14 12:17pm    
Post sample data and shortly describe what you mean by "not working"...
atul sharma 5126 19-Nov-14 12:30pm    
Thanks for the reply!
The problem is that StdQty is coming Null when actually their is data in the table.
The possible reason i am sighting is that the BOM.BOMMN is a string= Machine''

Also, when I create a right join, all data from BOM table is shown for field StdQty, hence I cam presume that the field reference is correct and the problem lies somewhere in joining.
Shweta N Mishra 19-Nov-14 12:33pm    
if BOM.BOMMN is a string= Machine'' then whats there in PBOM.PBOMM
atul sharma 5126 19-Nov-14 12:37pm    
Hello Shweta! Sorry but I could not get your query.

They are the two fields on which I have created the Join. and Machine'' is a sample of data in fields.

1 solution

Thanks all. Problem found. In one table the user has entered single quotes twice and in the other the different user has entered double quotes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900