Advertisement
scottashipp

Untitled

Mar 29th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. EXEC retrieve_customers_by_location 'Seattle','WA','98144','USA'
  2.  
  3. CREATE PROC retrieve_customers_by_location(
  4. @city NVARCHAR(100),
  5. @state NVARCHAR(2),
  6. @zip NVARCHAR(9),
  7. @country NVARCHAR(10)
  8. )
  9. As
  10.  
  11. Begin
  12.  
  13. select * from customers where city=@city and state=@state and zip=@zip and country = @country
  14.  
  15. End
  16.  
  17.  
  18. select * from customers
  19. where
  20. (city = @city or @city is null) and
  21. (state= @state or @state is null) and
  22. (zip = @zip or @zip is null) and
  23. (country = @country or @country is null)
  24.  
  25. ID
  26. FIRST
  27. LAST
  28. CITY
  29. STATE
  30. ZIP
  31. COUNTRY
  32. 1
  33. Joe
  34. Public
  35. Seattle
  36. WA
  37. 98144
  38. USA
  39. 2
  40. Jane
  41. Public
  42. Amsterdam
  43. BT
  44. 1063
  45. NLD
  46. 3
  47. Jennifer
  48. Public
  49. Miami
  50. FL
  51. 33101
  52. NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement