Home not get record from database to itemcode have spaces although i use ltrim
Reply: 0

not get record from database to itemcode have spaces although i use ltrim

user3223372
1#
user3223372 Published in 2018-02-14 08:52:18Z

problem

when match item code with item code have spaces by ltrim it get null result

Details

I make SQL query to get latest prices for customer from database

correct result is 13.5 price value

but it give me null

the problem in item code have spaces IN item code in database so that i dont

know how to match item code have spaces to get correct result

my query as following

string MaxPrice = @"SELECT   max(  dbo.TrxInvf.Price)
                                FROM         dbo.TrxInvF INNER JOIN
                                dbo.TrxInvH ON dbo.TrxInvF.BranchCode = dbo.TrxInvH.BranchCode AND dbo.TrxInvF.Trxtype = dbo.TrxInvH.Trxtype AND 
                                dbo.TrxInvF.TrxYear = dbo.TrxInvH.TrxYear AND dbo.TrxInvF.TrxSerial = dbo.TrxInvH.TrxSerial INNER JOIN
                                dbo.trxtypeConfig ON dbo.TrxInvF.BranchCode = dbo.trxtypeConfig.BranchCode AND dbo.TrxInvF.Trxtype = dbo.trxtypeConfig.trxtypecode
                                WHERE     (dbo.trxtypeConfig.TrxTypeID = 2) AND (dbo.trxtypeConfig.TrxKind = 1) AND (dbo.TrxInvH.TargetType = 1) AND (dbo.TrxInvH.TargetCode = " + Customercode + @") AND ( ltrim( dbo.TrxInvf.ItemCode) = '" + codeitem + @"') 
                                and TrxDate = (
                                SELECT   max(  dbo.TrxInvH.TrxDate)
                                FROM         dbo.TrxInvF INNER JOIN
                                dbo.TrxInvH ON dbo.TrxInvF.BranchCode = dbo.TrxInvH.BranchCode AND dbo.TrxInvF.Trxtype = dbo.TrxInvH.Trxtype AND 
                                dbo.TrxInvF.TrxYear = dbo.TrxInvH.TrxYear AND dbo.TrxInvF.TrxSerial = dbo.TrxInvH.TrxSerial INNER JOIN
                                dbo.trxtypeConfig ON dbo.TrxInvF.BranchCode = dbo.trxtypeConfig.BranchCode AND dbo.TrxInvF.Trxtype = dbo.trxtypeConfig.trxtypecode
                                WHERE     (dbo.trxtypeConfig.TrxTypeID = 2) AND (dbo.trxtypeConfig.TrxKind = 1) AND (dbo.TrxInvH.TargetType = 1) AND (dbo.TrxInvH.TargetCode = " + Customercode + @") AND ( ltrim (dbo.TrxInvf.ItemCode) = '" + codeitem + @"')  )";

the problem in item code have spaces so that i cannot match the value of item to get value .

so that how to match item code to get correct value from database as last

price for customers .

in debugger in visual studio 2015 my query above as following without using

variable :

SELECT   max(  dbo.TrxInvf.Price)
                                FROM         dbo.TrxInvF INNER JOIN
                                dbo.TrxInvH ON dbo.TrxInvF.BranchCode = dbo.TrxInvH.BranchCode AND dbo.TrxInvF.Trxtype = dbo.TrxInvH.Trxtype AND 
                                dbo.TrxInvF.TrxYear = dbo.TrxInvH.TrxYear AND dbo.TrxInvF.TrxSerial = dbo.TrxInvH.TrxSerial INNER JOIN
                                dbo.trxtypeConfig ON dbo.TrxInvF.BranchCode = dbo.trxtypeConfig.BranchCode AND dbo.TrxInvF.Trxtype = dbo.trxtypeConfig.trxtypecode
                                WHERE     (dbo.trxtypeConfig.TrxTypeID = 2) AND (dbo.trxtypeConfig.TrxKind = 1) AND (dbo.TrxInvH.TargetType = 1) AND (dbo.TrxInvH.TargetCode = 125204) AND ( ltrim( dbo.TrxInvf.ItemCode) = '            10200025') 
                                and TrxDate = (
                                SELECT   max(  dbo.TrxInvH.TrxDate)
                                FROM         dbo.TrxInvF INNER JOIN
                                dbo.TrxInvH ON dbo.TrxInvF.BranchCode = dbo.TrxInvH.BranchCode AND dbo.TrxInvF.Trxtype = dbo.TrxInvH.Trxtype AND 
                                dbo.TrxInvF.TrxYear = dbo.TrxInvH.TrxYear AND dbo.TrxInvF.TrxSerial = dbo.TrxInvH.TrxSerial INNER JOIN
                                dbo.trxtypeConfig ON dbo.TrxInvF.BranchCode = dbo.trxtypeConfig.BranchCode AND dbo.TrxInvF.Trxtype = dbo.trxtypeConfig.trxtypecode
                                WHERE     (dbo.trxtypeConfig.TrxTypeID = 2) AND (dbo.trxtypeConfig.TrxKind = 1) AND (dbo.TrxInvH.TargetType = 1) AND (dbo.TrxInvH.TargetCode = 125204) AND ( ltrim (dbo.TrxInvf.ItemCode) = '            10200025')  )
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311185 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO