Files
2026-04-23 21:38:24 -04:00

31 lines
851 B
Transact-SQL

-- Check quote QT-2602-0050 and its customer
DECLARE @QuoteNumber NVARCHAR(50) = 'QT-2602-0050';
-- Find the quote and customer info
SELECT
q.Id AS QuoteId,
q.QuoteNumber,
q.CustomerId,
CASE WHEN q.CustomerId IS NULL THEN 1 ELSE 0 END AS IsProspect,
q.ProspectCompanyName,
q.ProspectContactName,
q.IsDeleted AS QuoteIsDeleted,
c.Id AS CustomerIdFromTable,
c.CompanyName AS CustomerCompanyName,
c.IsDeleted AS CustomerIsDeleted
FROM Quotes q
LEFT JOIN Customers c ON q.CustomerId = c.Id
WHERE q.QuoteNumber = @QuoteNumber;
-- Show all prospect and customer fields
SELECT
QuoteNumber,
CustomerId,
CASE WHEN CustomerId IS NULL THEN 'YES' ELSE 'NO' END AS IsProspect,
ProspectCompanyName,
ProspectContactName,
ProspectEmail,
ProspectPhone
FROM Quotes
WHERE QuoteNumber = @QuoteNumber;