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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Retrieve all column if parameter is null

Retrieve all column if parameter is null

Scheduled Pinned Locked Moved Database
database
5 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.
  • A Offline
    A Offline
    angelagke
    wrote on last edited by
    #1

    How I write the condition of SQL statement to retrieve all author's name from database pubs if passing parameter is null and if user insert an author's name, then only particular name will be display.. thanks angela

    N 1 Reply Last reply
    0
    • A angelagke

      How I write the condition of SQL statement to retrieve all author's name from database pubs if passing parameter is null and if user insert an author's name, then only particular name will be display.. thanks angela

      N Offline
      N Offline
      nguyenvhn
      wrote on last edited by
      #2

      CREATE PROCEDURE GetAuthors @AuthorName nvarchar(100) AS IF @AuthorName IS NULL SELECT AuthorName FROM Author ELSE SELECT AuthorName FROM Author WHERE AuthorName=@AuthorName Is that one?

      A 1 Reply Last reply
      0
      • N nguyenvhn

        CREATE PROCEDURE GetAuthors @AuthorName nvarchar(100) AS IF @AuthorName IS NULL SELECT AuthorName FROM Author ELSE SELECT AuthorName FROM Author WHERE AuthorName=@AuthorName Is that one?

        A Offline
        A Offline
        angelagke
        wrote on last edited by
        #3

        when i run your SQL statement, it not return any value if i didn't insert author's name. I get another SQL statement that can solve my problem, Declare @au_lname char(30) Select @au_lname = '' select title, price, Name = substring (au_lname, 1,40), type from titleauthor ta JOIN authors a on ta.au_id = a.au_id JOIN titles t on ta.title_id = t.title_id Where 1 = Case When RTRIM(@au_lname) = '' Then 1 When RTRIM(@au_lname) <> '' And RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname)) Then 1 Else 0 End it's cool;) angela

        R 1 Reply Last reply
        0
        • A angelagke

          when i run your SQL statement, it not return any value if i didn't insert author's name. I get another SQL statement that can solve my problem, Declare @au_lname char(30) Select @au_lname = '' select title, price, Name = substring (au_lname, 1,40), type from titleauthor ta JOIN authors a on ta.au_id = a.au_id JOIN titles t on ta.title_id = t.title_id Where 1 = Case When RTRIM(@au_lname) = '' Then 1 When RTRIM(@au_lname) <> '' And RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname)) Then 1 Else 0 End it's cool;) angela

          R Offline
          R Offline
          r stropek
          wrote on last edited by
          #4

          Hi! You can simplify this statement:

          Declare @au_lname char(30)
          Select @au_lname = ''

          select title, price, Name = substring (au_lname, 1,40), type
          from titleauthor ta
          JOIN authors a on ta.au_id = a.au_id
          JOIN titles t on ta.title_id = t.title_id
          where RTRIM(@au_lname) = ''
          or RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname))

          Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers

          A 1 Reply Last reply
          0
          • R r stropek

            Hi! You can simplify this statement:

            Declare @au_lname char(30)
            Select @au_lname = ''

            select title, price, Name = substring (au_lname, 1,40), type
            from titleauthor ta
            JOIN authors a on ta.au_id = a.au_id
            JOIN titles t on ta.title_id = t.title_id
            where RTRIM(@au_lname) = ''
            or RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname))

            Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers

            A Offline
            A Offline
            angelagke
            wrote on last edited by
            #5

            ok, thanks for your solution angela

            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