Guest User

gettrans

a guest
Mar 19th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. USE [SpendAl]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[GetTransactions] Script Date: 03/19/2011 22:48:41 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. -- drop procedure GetTransactions
  10. ALTER PROCEDURE [dbo].[GetTransactions]
  11.  
  12. @CustomerId INT = NULL
  13.  
  14. AS
  15.  
  16. BEGIN
  17.  
  18.  
  19. INSERT INTO App_Log
  20. (Info, Start, EndDate)
  21. VALUES
  22. ('GetTransactions', getDate(), null )
  23. Declare @logId int
  24. SET @logId = @@IDENTITY
  25.  
  26. SET NOCOUNT ON;
  27.  
  28. SELECT LTRIM(RTRIM(ISNULL(d.DepartmentName, ''))) AS DepartmentName
  29. ,d.DepartmentId AS DepartmentId
  30. ,ISNULL(t.Cost, 0) AS Expense
  31. ,ISNULL(t.Quantity , 0)AS Quantity
  32. ,LTRIM(RTRIM(ISNULL(c.CustomerName, ''))) AS CUSTNAME
  33. ,LTRIM(RTRIM(ISNULL(i.ItemName, ''))) AS Description
  34. ,t.DateCreated AS DateCreated
  35. ,LTRIM(RTRIM(ISNULL(ct.CategoryLongName, ''))) AS CategoryName
  36. ,LTRIM(RTRIM(ISNULL(ct.CategoryName, ''))) AS USCATVAL
  37. --,'00000' AS Budget
  38. ,LTRIM(RTRIM(ISNULL(t.InvoiceNumber,''))) as InvoiceNum
  39. FROM Transactions t
  40. LEFT JOIN Departments d ON t.DepartmentId = d.DepartmentId
  41. LEFT JOIN Customers c ON t.CustomerId = c.CustomerId
  42. LEFT JOIN Categories ct ON t.CategoryId = ct.CategoryId
  43. LEFT JOIN Items i ON t.ItemId = i.ItemId
  44. WHERE DateCreated >= DATEADD(YYYY, - 2, GETDATE())
  45. AND DateCreated <= GETDATE()
  46. AND t.CustomerId = @CustomerId
  47. ORDER BY DateCreated DESC
  48.  
  49.  
  50.  
  51. UPDATE App_Log
  52. SET EndDate = GETDATE()
  53. where ID = @logId
  54.  
  55. END
Advertisement
Add Comment
Please, Sign In to add comment