动态查询以查找特定模式 [英] Dynamic query to find a particular pattern
问题描述
我有一个由许多数据库组成的服务器。
所有数据库中都有一个公共视图(v_xyz)。此视图由多列组成。(列A,列
B,.....)
列A由产品ID组成和B列包含可以找到这些产品ID的路径。
我需要检查所有数据库是否在数据库中的2个不同路径中存在任何产品ID 。
路径可能包含'%pqr%'或'%abc%'等字样
我尝试了什么:
所以我尝试使用like子句,但我不得不经常更改数据库。
请帮忙。
I have a single server consisting of many database.
There is a common view(v_xyz) which exists in all the database. This view consists of multiple columns.(column A, Column
B,.....)
Column A consists of Product Ids and Column B consists of Path where these Product Ids can be found.
I need to check in all the database whether any Product Ids exists in 2 different paths across the database.
Path could consists of words like '%pqr%' or '%abc%'
What I have tried:
So I tried using the like clause but i have to change the database every now and then.
Please help.
推荐答案
你可以创建这样的视图
You can create view something like this
CREATE VIEW ViewName
AS
SELECT ColumnName FROM [Database1].[Database].dbo.TableName
UNION ALL
SELECT ColumnName [Database2].dbo.TableName
UNION ALL
SELECT ColumnName FROM [Database3].dbo.TableName
之后你可以根据需要做你的逻辑。
After that you can do your logic according to your need.
这篇关于动态查询以查找特定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!