Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Statement Result Based on String Function 1

Status
Not open for further replies.

bustercoder

Programmer
Mar 13, 2007
96
Hello,

This select is used to populate a drop-down in a report, showing the cust# and name concatenated and is used as an input parameter for a stored proc:

SELECT DISTINCT [CUSTOMER] = LTRIM(RTRIM(RM00101.CUSTNMBR)) + ' - ' + LTRIM(RTRIM(RM00101.CUSTNAME))
FROM RM00101
WHERE RM00101.CUSTNAME <> ''

So, I am trying to take everything to the right of the dash and use that as the input parameter, as shown in this excerpt from my stored proc:

@customer varchar(50)

SELECT
RM30201.CUSTNMBR,
RM30201.APFRDCNM
FROM
RM30201 INNER JOIN RM00101 ON RM30201.CUSTNMBR = RM00101.CUSTNMBR
WHERE
RM00101.CUSTNAME = {{STRING FN(@customer)}}

I was playing around with PATINDEX, SUBSTRING, RIGHT, different SQL functions, but can't seem to get it right. If someone could show me I would sure appreciate it. It would be a good learning exercise for future.

Thanks,
Buster
 
This?

Code:
Declare @Temp VarChar(100)
Set @Temp = 'Hello - World'

Select ltrim(Right(@Temp, Len(@Temp) - CharIndex('-', @Temp)))

-George

"the screen with the little boxes in the window." - Moron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top