2
Answers

Returns double values

Photo of Janine

Janine

14y
2.4k
1

Hi am writing a sql query that should return multiple values from mulitple tables, that part works (whoopee) but it is returning the same employee multiple times. One of the values I am returning contains many similarites in them form example "BankAL, BankAAL, BankALE, BankALC, BankDTE" Lets say these are different Bank categories. Now an Employee can belong to just one of these categories, or all of them, or just some of them.
The user of this proc knows the Bank part, thats constant. So they just want the first two characters displayed after Bank. eg. "AL, AA, DT" This can be done, but I am assuming I am getting multiple values or the same employee multiple times because one employee can belong to BankAL and BankALC, even though I am displaying only AL, i think it still reads both and therefore would display the employee twice. (like I said, I think)
 
This is the case statement I am using to only select the "AL" part, but it doesn't sort out the problem
@SQL
= @SQL + 'CASE WHEN OEMPBANK.BankID LIKE ''Bank%'' THEN IsNull(SUBSTRING(OEMPBANK.BankID , 5, 2),'' '') ELSE ' ' END
As you can imagine this is sensitive info so cant post too much code

Answers (2)

0
Photo of Sam Hobbs
NA 28.7k 1.3m 14y

The main problem with answeriing your question is that the question is not clear. It is not clear to me what the data is and how you need to process it.
 
You say "just want the first two characters", implying you need to show bank categories, but you also say "same employee multiple times" and "one employee can belong". I am not experienced enough with SQL enough to help much, but I think there is a SQL option to eliminate duplicates.
0
Photo of Jaish Mathews
NA 7.3k 1.2m 14y

Hi,
I hope you will get specific answers from our sister community meant for DB people.
http://www.c-sharpcorner.com/News/NewsDetail.aspx?NewsID=649