December 12, 2005 at 8:42 am
Hey i want to join two part numbers but in some case there is a part number with a space in it this is caused by user input error,
Example part1_id = 123 456, part2_id = 123456
If i do a join on this it may or may not pick it up how do i get my query to join the 123456 togeter, as in look for a space join the number up together...
Thanks
December 12, 2005 at 8:52 am
From BOL:
Replaces all occurrences of the second given string expression in the first string expression with a third expression.
REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )
declare @MyString varchar(20)
set @MyString = '123 456'
select replace(@MyString, ' ','')
----------------------------------------------
123456
December 12, 2005 at 8:57 am
You can use replace() on the idcolumns to replace spaces with empty strings.
replace(id1, ' ','') = replace(id2,' ', '')
Note though that this will invalidate any indexusage on those columns enclosed by the functions.
What you really should try to do, is to clean the data once and for all, or even better, make sure that users can't enter id's with embedded spaces for starters. One also wonders how an ID number can be entered by a user..?
Though, if you're stuck between a rock and a hard place, replace() will let you work around the immediate problem, though it's not solved. You have corrupt id-values in there, and they should be taken care of.
Good luck
/Kenneth
December 12, 2005 at 9:17 am
Thanks,
Here is my code.
select ol.supplier_Part_Number,pd.pronum
from dw..products_dim pd
inner join ORDER_LINES ol on ol.supplier_Part_Number = pd.pronum
so how do i intergrate the code into it ?
December 12, 2005 at 9:46 am
Thanks its working fine now.
December 12, 2005 at 7:05 pm
It's customary to share your final solution, if you don't mind.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 13, 2005 at 12:10 pm
Users should not be entering parts ID numbers. Let them choose from a list of pre-existing, un-editable IDs.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply