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. Correct this sql

Correct this sql

Scheduled Pinned Locked Moved Database
databasetutorialquestion
7 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
    Abdul Rhman Alsri
    wrote on last edited by
    #1

    How to form this logic in a true sql? Select * from AdCampaign where category and language and keyword in (select sitecategory, language, keyword from Adzone)

    L 1 Reply Last reply
    0
    • A Abdul Rhman Alsri

      How to form this logic in a true sql? Select * from AdCampaign where category and language and keyword in (select sitecategory, language, keyword from Adzone)

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      You can use a join. Use something like this:

      select a.* from AdCampaign a inner join Adzone b
      on a.category=b.sitecategory and a.language=b.language and a.keyword=b.keyword;

      A 1 Reply Last reply
      0
      • L loyal ginger

        You can use a join. Use something like this:

        select a.* from AdCampaign a inner join Adzone b
        on a.category=b.sitecategory and a.language=b.language and a.keyword=b.keyword;

        A Offline
        A Offline
        Abdul Rhman Alsri
        wrote on last edited by
        #3

        Could I replaceany of the dqual "=" into "like"?

        L 1 Reply Last reply
        0
        • A Abdul Rhman Alsri

          Could I replaceany of the dqual "=" into "like"?

          L Offline
          L Offline
          loyal ginger
          wrote on last edited by
          #4

          You will need to give further details about your requirement. What do you want to achieve with "like"? In SQL "like" matches a pattern, similar to using wild cards. In your case, you seem to mean something else. I may not be able to answer your question, but if you offer more details, somebody else may have an answer.

          A 1 Reply Last reply
          0
          • L loyal ginger

            You will need to give further details about your requirement. What do you want to achieve with "like"? In SQL "like" matches a pattern, similar to using wild cards. In your case, you seem to mean something else. I may not be able to answer your question, but if you offer more details, somebody else may have an answer.

            A Offline
            A Offline
            Abdul Rhman Alsri
            wrote on last edited by
            #5

            I had an error with % at end of query <pre>select a.AdHeadline,a.AdText,a.DisplayUrl, a.TargetUrl from AdCampaign a inner join Adzone b on a.sitecategory=b.category and a.language=b.language and a.keyword like %b.keyword%;</pre> Error: Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'b'.

            A S 2 Replies Last reply
            0
            • A Abdul Rhman Alsri

              I had an error with % at end of query <pre>select a.AdHeadline,a.AdText,a.DisplayUrl, a.TargetUrl from AdCampaign a inner join Adzone b on a.sitecategory=b.category and a.language=b.language and a.keyword like %b.keyword%;</pre> Error: Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'b'.

              A Offline
              A Offline
              Abdul Rhman Alsri
              wrote on last edited by
              #6

              make it as

              '%'+b.keyword+'%'

              1 Reply Last reply
              0
              • A Abdul Rhman Alsri

                I had an error with % at end of query <pre>select a.AdHeadline,a.AdText,a.DisplayUrl, a.TargetUrl from AdCampaign a inner join Adzone b on a.sitecategory=b.category and a.language=b.language and a.keyword like %b.keyword%;</pre> Error: Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'b'.

                S Offline
                S Offline
                Simon_Whale
                wrote on last edited by
                #7

                USE pubs IF EXISTS (SELECT name FROM sysobjects WHERE name = 'au_info2' AND type = 'P') DROP PROCEDURE au_info2 GO USE pubs GO CREATE PROCEDURE au_info2 @lastname varchar(30) = 'D%', @firstname varchar(18) = '%' AS SELECT au_lname, au_fname, title, pub_name FROM authors a INNER JOIN titleauthor ta ON a.au_id = ta.au_id INNER JOIN titles t ON t.title_id = ta.title_id INNER JOIN publishers p ON t.pub_id = p.pub_id WHERE au_fname LIKE @firstname AND au_lname LIKE @lastname this example was taken from msdn like examples

                Marc Clifton wrote:

                That has nothing to do with VB. - Oh crap. I just defended VB!

                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