TSQL - compare tables
- by Rya
I want to create a stored procedure that compares the results of two queries. If the results of the 2nd table can be found in the first, print 'YES', otherwise, print 'No'.
Table 1:
SELECT dbo.Roles.RoleName, dbo.UserRoles.RoleID
FROM dbo.Roles LEFT OUTER JOIN
dbo.UserRoles ON dbo.Roles.RoleID = dbo.UserRoles.RoleID
WHERE (dbo.Roles.PortalID = 0) AND (dbo.UserRoles.UserID = 2)
Table 2:
Declare @RowData as nvarchar(2000)
Set @RowData = ( SELECT EditPermissions FROM vw_XMP_DMS_Documents where DocumentID = 2)
Select Data
from dbo.split(@RowData, ',')
For example.
Table 1:
John
Jack
James
Table 2:
John
Sally
Jane
Print 'YES'
Is this possible???
Thank you all very much.
-R