The Field list which is comma separated is being read as a literal string, not comma separated values. You have to use dynamic SQL or otherwise separate the comma values into a 1 colum list to use them as a where condition.Dynamic SQL isn't the best option.But you could use what you have by making it dynamic as followsDeclare @ColorList varchar(255)Declare @SQL varchar(3000)SELECT @ColorList=Coalesce(@ColorList + ', ', '') + Cast(Color.Name AS varchar(15))FROM Article INNER JOIN ArticleColorWay ON Article.ID = ArticleColorWay.ArticleID INNER JOIN Color ON ArticleColor.ColorID = Color.ColorNo INNER JOIN ArticleCategory ON Article.Category=ArticleCategory.NumberWHERE Article.category = @CatSelect @SQL = 'SELECT '+@ColorList + ', Color.Name as ColorName, Article.Name AS ArticleNameFROM Article INNER JOIN ArticleColorWay ON Article.ID = ArticleColorWay.ArticleID INNER JOIN Color ON ArticleColor.ColorID = Color.ColorNo INNER JOIN ArticleCategory ON Article.Category=ArticleCategory.NumberWHERE Article.category = ' + convert(varchar,@Cat)Exec (@SQL)
Note..without table structure DDL or expected results, the above syntax may not work for you, but essentially dynamic SQL is building the select statement in a string, then execute that string as a SQL statement using EXECUTE
Poor planning on your part does not constitute an emergency on my part.