Click here to Skip to main content
15,125,002 members
Home / Discussions / Database
   

Database

 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 6:32
MemberJassim Rahma13-Aug-16 6:32 
GeneralRe: Error when passing multiple values Pin
Richard MacCutchan13-Aug-16 7:03
mveRichard MacCutchan13-Aug-16 7:03 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 8:08
MemberJassim Rahma13-Aug-16 8:08 
GeneralRe: Error when passing multiple values Pin
Richard MacCutchan13-Aug-16 9:29
mveRichard MacCutchan13-Aug-16 9:29 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 12:12
MemberJassim Rahma13-Aug-16 12:12 
GeneralRe: Error when passing multiple values Pin
Victor Nijegorodov13-Aug-16 12:15
MemberVictor Nijegorodov13-Aug-16 12:15 
GeneralRe: Error when passing multiple values Pin
Jassim Rahma13-Aug-16 12:21
MemberJassim Rahma13-Aug-16 12:21 
GeneralRe: Error when passing multiple values Pin
Mycroft Holmes13-Aug-16 15:04
professionalMycroft Holmes13-Aug-16 15: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 9:16
MemberJassim Rahma15-Aug-16 9:16 
GeneralRe: Error when passing multiple values Pin
Mycroft Holmes15-Aug-16 14:02
professionalMycroft Holmes15-Aug-16 14:02 
QuestionHow do Coders Get Database Experts? For a project Pin
TheOnlyRealTodd8-Aug-16 21:58
professionalTheOnlyRealTodd8-Aug-16 21:58 
AnswerRe: How do Coders Get Database Experts? For a project Pin
Mycroft Holmes9-Aug-16 14:04
professionalMycroft Holmes9-Aug-16 14:04 
AnswerRe: How do Coders Get Database Experts? For a project Pin
Nathan Minier10-Aug-16 2:21
professionalNathan Minier10-Aug-16 2:21 
AnswerRe: How do Coders Get Database Experts? For a project Pin
jschell12-Aug-16 12:15
Memberjschell12-Aug-16 12:15 
QuestionHow to pass varchar as WHERE field IN param Pin
Jassim Rahma5-Aug-16 6:14
MemberJassim Rahma5-Aug-16 6:14 
AnswerRe: How to pass varchar as WHERE field IN param Pin
Mycroft Holmes5-Aug-16 14:04
professionalMycroft Holmes5-Aug-16 14:04 
AnswerRe: How to pass varchar as WHERE field IN param Pin
David Mujica9-Aug-16 7:20
MemberDavid Mujica9-Aug-16 7:20 
QuestionIs this SQL query about getting information from all forum users' unread PMs? Pin
Member 1266244831-Jul-16 2:41
MemberMember 1266244831-Jul-16 2:41 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Eddy Vluggen31-Jul-16 3:20
professionalEddy Vluggen31-Jul-16 3:20 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624481-Aug-16 3:04
MemberMember 126624481-Aug-16 3:04 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Eddy Vluggen1-Aug-16 8:35
professionalEddy Vluggen1-Aug-16 8:35 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
User 1106097931-Jul-16 3:23
MemberUser 1106097931-Jul-16 3:23 
GeneralRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624481-Aug-16 3:01
MemberMember 126624481-Aug-16 3:01 
QuestionRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
User 110609791-Aug-16 3:07
MemberUser 110609791-Aug-16 3:07 
AnswerRe: Is this SQL query about getting information from all forum users' unread PMs? Pin
Member 126624485-Aug-16 2:04
MemberMember 126624485-Aug-16 2: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.