Я довольно новичок в SQL Server, но мне нужно написать хранимую процедуру, которая будет искать определенную таблицу со списком ключевых слов, и она должна возвращать строки, которые были найдены, I написал запрос, который работает, но проблемы в том, когда мне нужно внести изменения в список ключевых слов, тогда я должен начать с нуля с написания запроса.Ключевое слово SQL Server хранимой процедуры
Запрос выглядит следующим образом
SELECT *
INTO [playground].[dbo].[New table name]
FROM [playground].[dbo].[Main table]
WHERE [Document Type Description] LIKE 'Alcohol'
OR [Document Type Description] LIKE 'DSTV'
OR [Document Type Description] LIKE 'Entertainment' OR
[Document Type Description]like'Bday' OR
[Document Type Description]like'Birthday' OR
[Document Type Description]like'Bar' OR
[Document Type Description]like'Booze' OR
[Document Type Description]like'Catering' OR
[Document Type Description]like'Farewell' OR
[Document Type Description]like'Food' OR
[Document Type Description]like'Function' OR
[Document Type Description]like'Meals' OR
[Document Type Description]like'Year end functions' OR
[Document Type Description]like'Womens day' OR
[Document Type Description]like'Womans day' OR
[Document Type Description]like'Tuck shop' OR
[Document Type Description]like'Teambuilding' OR
[Document Type Description]like'Refreshment' OR
[Document Type Description]like'Liquor' OR
[Document Type Description]like'Lunch' OR
[Document Type Description]like'Water' OR
[Document Type Description]like'Bread' OR
[Document Type Description]like'Breakaway' OR
[Document Type Description]like'Canteen' OR
[Document Type Description]like'Gifts' OR
[Document Type Description]like'Glass' OR
[Document Type Description]like'Glasses' OR
[Document Type Description]like'Glassware' OR
[Document Type Description]like'Ticket' OR
[Document Type Description]like'Rugby' OR
[Document Type Description]like'Cricket' OR
[Document Type Description]like'Tea cups' OR
[Document Type Description]like'Tea' OR
[Document Type Description]like'Sugar bowl' OR
[Document Type Description]like'Sugar' OR
[Document Type Description]like'Soup bowls' OR
[Document Type Description]like'Side plate' OR
[Document Type Description]like'Serving tray' OR
[Document Type Description]like'Saucers' OR
[Document Type Description]like'Tray' OR
[Document Type Description]like'Non slip tray' OR
[Document Type Description]like'Milk' OR
[Document Type Description]like'Milk jug' OR
[Document Type Description]like'Mugs' OR
[Document Type Description]like'Dessert' OR
[Document Type Description]like'Dessert spoons' OR
[Document Type Description]like'Dinner set' OR
[Document Type Description]like'Jug' OR
[Document Type Description]like'Kent' OR
[Document Type Description]like'Knifes' OR
[Document Type Description]like'Knives' OR
[Document Type Description]like'Cooler boxes' OR
[Document Type Description]like'Crockery' OR
[Document Type Description]like'Christmas' OR
[Document Type Description]like'Coffee' OR
[Document Type Description]like'Popcorn machine' OR
[Document Type Description]like'Cooler' OR
[Document Type Description]like'Freezer' OR
[Document Type Description]like'Fridge' OR
[Document Type Description]like'Fan ' OR
[Document Type Description]like'Extraction fan' OR
[Document Type Description]like'Heaters' OR
[Document Type Description]like'Water cooler' OR
[Document Type Description]like'Washing machine' OR
[Document Type Description]like'Warmer' OR
[Document Type Description]like'Vacuum cleaner' OR
[Document Type Description]like'Urn' OR
[Document Type Description]like'Thermostat'
В конце концов, я хочу, чтобы у меня есть SP, который будет читать массив ключевых слов и позвольте мне выбрать, какие таблицы столбец для поиска в основных таблицах
Надежда это имеет смысл Заранее спасибо
Поместите эти строки в TABLE и JOIN на равенство с [Тип документа Описание] Вы можете добавить еще один столбец, чтобы контролировать их включение. –
@AlexK. OP использует 'like', а не равенство. Есть ли способ сделать то, что вы описали, используя семантику сравнения «как» в SQL Server? –
На самом деле он ищет равенства (нет никаких подстановочных знаков, он говорит, что он работает так, как ожидалось) - И да, вы можете «ПРИСОЕДИНЯЙТЕСЬ НА X LIKE»% '+ Y +'% ''- –