19

declare @username varchar(255)
if @username is null
set @username = suser_name()

.........

WHAT DID YOU EXPECT @USERNAME TO BE RIGHT AFTER YOU DECLARED IT???

Comments
  • 1
    Not like that but I sometimes add extra safety checks in my code so that if someone else uses it and modifies without caring the app doesn't crash.

    I've seen people that focus on "declare ...."
    and never notice what's after it, which in your case checking if still null then assign a value.
  • 4
    @gitpush From your avatar, I surmise that we are long-lost brothers.
  • 1
    Either something was forgotten, or more likely, removed without rewriting the code.

    I often see similar things when refactoring old code, often a bit more obscure but the same flow.
  • 1
    OR the coder is incompetent.
    Occam’s Razor.
  • 0
    Could it be declared and assigned elsewhere?
  • 0
    @ravijojila You are imagining a scenario that exceeds technical capacity of the creator.
Add Comment