T-SQL newbie here. I am sure you guys can help me with a little problem I'm having.
Here's my situation:
I want to do a select from a certain table. And with that select I want to display the count of a referenced entry in another table.
So here's my script:
/****** Skript für SelectTopNRows-Befehl aus SSMS ******/ SELECT [ID] ,[ExpenseNumber] ,[Mandator] -- some more rows here -- Memo ,(SELECT COUNT(*) FROM [Foobar].[dbo].[MemoUnion] WHERE ([Mandator] = 096) AND ([ReferenceType] = 4001) AND ([Reference] COLLATE SQL_Latin1_General_CP1_CI_AS = [ID])) AS [MemoCount] FROM [Foobar].[dbo].[Expense] WHERE Mandator = 096 AND ExpenseNumber = 1;
So here's my problem, the column
[MemoCount] shows 0, although I am 100% sure that there is an actual entry in
Reference = ID is actually true.
My suspicion is that it's not working because
[ID] is an
So I fiddled around with
CAST(). But the result stays 0 none the less.
I did not get any error messages while using
CAST. Just always a result of 0.
Thanks in advance