Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MSSQL Question

MSSQL Question

Scheduled Pinned Locked Moved Database
questionsql-server
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wouter Coinless
    wrote on last edited by
    #1

    Is there a way to do this:

    @FirstId uniqueidentifier = NULL;
    @SecondId uniqueidentifier = NULL;

    SELECT ..
    FROM ..
    WHERE
    IF(@FirstId IS NOT NULL)
    BEGIN
    FirstId = @FirstId
    END
    IF(@SecondId IS NOT NULL)
    BEGIN
    AND FirstId = @FirstId
    END

    Or a smarter way? :D Thanks in advance!

    L 1 Reply Last reply
    0
    • W Wouter Coinless

      Is there a way to do this:

      @FirstId uniqueidentifier = NULL;
      @SecondId uniqueidentifier = NULL;

      SELECT ..
      FROM ..
      WHERE
      IF(@FirstId IS NOT NULL)
      BEGIN
      FirstId = @FirstId
      END
      IF(@SecondId IS NOT NULL)
      BEGIN
      AND FirstId = @FirstId
      END

      Or a smarter way? :D Thanks in advance!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, this is what I would try:

      ... WHERE (@FirstId=null OR FirstId=@FirstId) AND (@SecondId =null OR SecondId =@SecondId )

      :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      Local announcement (Antwerp region): Lange Wapper? Neen!


      W 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, this is what I would try:

        ... WHERE (@FirstId=null OR FirstId=@FirstId) AND (@SecondId =null OR SecondId =@SecondId )

        :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        Local announcement (Antwerp region): Lange Wapper? Neen!


        W Offline
        W Offline
        Wouter Coinless
        wrote on last edited by
        #3

        I dont want to include the Ids if they are null.

        J 1 Reply Last reply
        0
        • W Wouter Coinless

          I dont want to include the Ids if they are null.

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          The suggestion given does exactly what you want it to do.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups