Click here to Skip to main content
15,886,740 members
Home / Discussions / Database
   

Database

 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 5:32
Jassim Rahma13-Aug-16 5:32 
GeneralRe: Error when passing multiple values Pin
Richard MacCutchan13-Aug-16 6:03
mveRichard MacCutchan13-Aug-16 6:03 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 7:08
Jassim Rahma13-Aug-16 7:08 
GeneralRe: Error when passing multiple values Pin
Richard MacCutchan13-Aug-16 8:29
mveRichard MacCutchan13-Aug-16 8:29 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 11:12
Jassim Rahma13-Aug-16 11:12 
GeneralRe: Error when passing multiple values Pin
Victor Nijegorodov13-Aug-16 11:15
Victor Nijegorodov13-Aug-16 11:15 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 11:21
Jassim Rahma13-Aug-16 11:21 
GeneralRe: Error when passing multiple values Pin
Mycroft Holmes13-Aug-16 14:04
professionalMycroft Holmes13-Aug-16 14:04 
Sigh | :sigh: Does this not tell you something, SQL treats the parameter as a single value and you get an error! You need to split the string into individual values.

You need a split function for MySQL below is the SQL Server version I use
SQL
ALTER   FUNCTION [dbo].[fn_Split]
 (@List  varchar(8000), @Delimiter char(1))

RETURNS @Results table
 (Item varchar(8000),ID int Identity(1,1))

AS

begin
 declare @IndexStart int
 declare @IndexEnd int
 declare @Length  int
 declare @Word  varchar(8000)

 set @IndexStart = 1
 set @IndexEnd = 0

 set @Length = len(@List)
If @Delimiter = '' Set @Delimiter = ','

--Get rid of any tabs or returns
Set @List = Replace(@List,char(9),'')
Set @List = Replace(@List,char(10),'')
Set @List = Replace(@List,char(13),'')

while @IndexStart <= @Length
begin
    set @IndexEnd = charindex(@Delimiter, @List, @IndexStart)

    If @Delimiter = char(32) 
        set @IndexEnd = charindex(Space(1), @List, @IndexStart)

    if @IndexEnd = 0
        set @IndexEnd = @Length + 1

    set @Word = substring(@List, @IndexStart, @IndexEnd - @IndexStart)
    set @IndexStart = @IndexEnd + 1

    INSERT INTO @Results(Item)
    SELECT @Word
end

return
end 

Then you can use a join to filter the location table
SQL
DECLARE @StringParam VARCHAR(100)= 'AA,BB,CC'

--Test
SELECT * FROM dbo.fn_split(@StringParam,',')

SELECT * FROM Location L
INNER JOIN dbo.fn_split(@StringParam,',') S ON S.item = l.country_code

This is SQL Server code, you may need to change it for MySql
Never underestimate the power of human stupidity
RAH

GeneralRe: Error when passing multiple values Pin
Jassim Rahma15-Aug-16 8:16
Jassim Rahma15-Aug-16 8:16 
GeneralRe: Error when passing multiple values Pin
Mycroft Holmes15-Aug-16 13:02
professionalMycroft Holmes15-Aug-16 13:02 
QuestionHow do Coders Get Database Experts? For a project Pin
TheOnlyRealTodd8-Aug-16 20:58
professionalTheOnlyRealTodd8-Aug-16 20:58 
AnswerRe: How do Coders Get Database Experts? For a project Pin
Mycroft Holmes9-Aug-16 13:04
professionalMycroft Holmes9-Aug-16 13:04 
AnswerRe: How do Coders Get Database Experts? For a project Pin
Nathan Minier10-Aug-16 1:21
professionalNathan Minier10-Aug-16 1:21 
AnswerRe: How do Coders Get Database Experts? For a project Pin
jschell12-Aug-16 11:15
jschell12-Aug-16 11:15 
QuestionHow to pass varchar as WHERE field IN param Pin
Jassim Rahma5-Aug-16 5:14
Jassim Rahma5-Aug-16 5:14 
AnswerRe: How to pass varchar as WHERE field IN param Pin
Mycroft Holmes5-Aug-16 13:04
professionalMycroft Holmes5-Aug-16 13:04 
AnswerRe: How to pass varchar as WHERE field IN param Pin
David Mujica9-Aug-16 6:20
David Mujica9-Aug-16 6:20 
QuestionIs this SQL query about getting information from all forum users' unread PMs? Pin
Member 1266244831-Jul-16 1:41
Member 1266244831-Jul-16 1:41 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Eddy Vluggen31-Jul-16 2:20
professionalEddy Vluggen31-Jul-16 2:20 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624481-Aug-16 2:04
Member 126624481-Aug-16 2:04 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Eddy Vluggen1-Aug-16 7:35
professionalEddy Vluggen1-Aug-16 7:35 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
User 1106097931-Jul-16 2:23
User 1106097931-Jul-16 2:23 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624481-Aug-16 2:01
Member 126624481-Aug-16 2:01 
QuestionRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
User 110609791-Aug-16 2:07
User 110609791-Aug-16 2:07 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624485-Aug-16 1:04
Member 126624485-Aug-16 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.