My vendor sent over a piece of SQL code that I'm having a hell of a time getting to function with my existing query.
I have a webpage that is querying a database table for multiple values here's the code I have in the ASP page that queries SQL:
SELECT [Account],
[AccountName],
[ComputerName],
[EMail],
[Telephone],
[Status],
cast(cast([StartDate] as float) as datetime) as 'Start-Date',
cast(cast([LastBackupDate] as float) as datetime) as 'LastBackup-Date',
[TotalFileSize],
[TotalFileCount]
FROM ExpandedView WHERE loginid = @0
This query works great, but the "Account" field specified above apparently returns only part of the actual account number. Apparently my vendor uses a computation to create the final account number and they've sent it to me:
use <databasenamehere>
select left(
convert(nvarchar,E.Account)
,5)+'-'+convert(nvarchar,
( 50 +((E.Account)%10)
-((E.Account/10)%10)
+((E.Account/100)%10)
-((E.Account/1000)%10)
+((E.Account/10000)%10)
-((E.Account/100000)%10)
+((E.Account/1000000)%10)
-((E.Account/10000000)%10)
+((E.Account/100000000)%10))
%10 )
+right(convert(nvarchar,E.Account),4)
as 'Account', AccountName from ExpandView E
Inner Join Customer C
on E.Account=C.Account
Now I realize that that this query is selecting the first 5 numbers of the account number, appending the hyphen and then performing a mathematical procedure to the last 4 numbers, however I cannot figure out how to read this. Could I simply append these two statements together with an "AND" clause?
I really would like to understand what the "E.Account" refers to and why they use a "ExpandView E" and "Customer C" in the query. I'm also kind of lost how those relate to the actual tables.
Any assistance would be appreciated. Or if you prefer, post a link and I'll read up as best I can.
Thanks!