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. Problem when creating query on base of combination

Problem when creating query on base of combination

Scheduled Pinned Locked Moved Database
databasecsharpcomhelp
7 Posts 4 Posters 1 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.
  • R Offline
    R Offline
    Rupesh Kumar Swami
    wrote on last edited by
    #1

    hi all i want to prepare a query which returns the result on the basis of combination of character. In my MSAccess Database, table have two fields Id and Name Scenario is following 1 have 3 buttons with title "abc" ,"def","ghi" 1.if we first click on "abc" button then query must return the result for which name field begins with 'a' or 'b' or 'c' OR it contains " a"(space before a) or " b"(space before b) or " c"(space before c). 2. Now if we click on button "def" (remember that in previous step we click on "abc" button) then it must return the record that start with ('ad','bd','cd','ae','be','ce','af','bf','cf') OR it contains (' ad',' bd',' cd',' ae',' be',' ce',' af',' bf',' cf') means space before text and so on.. Please suggest me how can i build query for this type of condition.

    Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

    S N 2 Replies Last reply
    0
    • R Rupesh Kumar Swami

      hi all i want to prepare a query which returns the result on the basis of combination of character. In my MSAccess Database, table have two fields Id and Name Scenario is following 1 have 3 buttons with title "abc" ,"def","ghi" 1.if we first click on "abc" button then query must return the result for which name field begins with 'a' or 'b' or 'c' OR it contains " a"(space before a) or " b"(space before b) or " c"(space before c). 2. Now if we click on button "def" (remember that in previous step we click on "abc" button) then it must return the record that start with ('ad','bd','cd','ae','be','ce','af','bf','cf') OR it contains (' ad',' bd',' cd',' ae',' be',' ce',' af',' bf',' cf') means space before text and so on.. Please suggest me how can i build query for this type of condition.

      Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Hi, A complex problem, but perhaps this[^] thread might be useful. Regards, Syed Mehroz Alam.

      My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

      R 1 Reply Last reply
      0
      • S Syed Mehroz Alam

        Hi, A complex problem, but perhaps this[^] thread might be useful. Regards, Syed Mehroz Alam.

        My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

        R Offline
        R Offline
        Rupesh Kumar Swami
        wrote on last edited by
        #3

        Thanks syed, but it does not solve my problem

        Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

        1 Reply Last reply
        0
        • R Rupesh Kumar Swami

          hi all i want to prepare a query which returns the result on the basis of combination of character. In my MSAccess Database, table have two fields Id and Name Scenario is following 1 have 3 buttons with title "abc" ,"def","ghi" 1.if we first click on "abc" button then query must return the result for which name field begins with 'a' or 'b' or 'c' OR it contains " a"(space before a) or " b"(space before b) or " c"(space before c). 2. Now if we click on button "def" (remember that in previous step we click on "abc" button) then it must return the record that start with ('ad','bd','cd','ae','be','ce','af','bf','cf') OR it contains (' ad',' bd',' cd',' ae',' be',' ce',' af',' bf',' cf') means space before text and so on.. Please suggest me how can i build query for this type of condition.

          Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

          N Offline
          N Offline
          Niladri_Biswas
          wrote on last edited by
          #4

          Dear Rupesh, As I don't have MS Access in my system. So I was forced to solve the problem in SQL Server 2005. But the syntax will remain same in both the cases(or may be minor changes which I hope you can do). I have created a table[TBLSEARCH] with the following values

          a
          b
          c
          a
          b
          c
          AC
          AD
          AD
          AE
          AE
          AF
          AF
          AFGTHY
          BE
          BE

          And my Stored Proc goes like this

          **ALTER PROCEDURE sp_Search
          -- Add the parameters for the stored procedure here
          (@SEARCHSTRING VARCHAR(50))
          AS
          BEGIN
          -- SET NOCOUNT ON added to prevent extra result sets from
          -- interfering with SELECT statements.
          SET NOCOUNT ON;

          -- SEARCH WITH ABC COMBINATION
          IF(UPPER(@SEARCHSTRING) = 'ABC')
          
          	BEGIN
          		
          		SELECT \* 
          		FROM TBLSEARCH WHERE RTRIM(LTRIM(NAME)) LIKE '\[A-C\]%'
          
          	END
          
          -- SEARCH WITH DEF COMBINATION
          IF(UPPER(@SEARCHSTRING) = 'DEF')
          
          	BEGIN
          		
          		SELECT \* 
          		FROM TBLSEARCH WHERE 
          
          			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]%' OR
          
          			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]%' OR
          
          			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]%'
          
          	END
          
          -- SEARCH WITH GHI COMBINATION
          IF(UPPER(@SEARCHSTRING) = 'GHI')
          
          	BEGIN
          		
          		SELECT \* 
          		FROM TBLSEARCH WHERE 
          
          			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]\[GHI\]%' OR
          
          			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]\[GHI\]%' OR
          
          			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]\[GHI\]%'
          
          	END
          

          END
          GO**

          N.B.~ The @SEARCHSTRING can assume values either 'ABC' or 'DEF' or 'GHI' [ As your button names ] In my system I am getting the correct output. Please check it and let me know if it is working as per your expectation or not. Regards, Niladri Biswas :)

          Niladri Biswas

          modified on Wednesday, June 24, 2009 8:40 AM

          J R 2 Replies Last reply
          0
          • N Niladri_Biswas

            Dear Rupesh, As I don't have MS Access in my system. So I was forced to solve the problem in SQL Server 2005. But the syntax will remain same in both the cases(or may be minor changes which I hope you can do). I have created a table[TBLSEARCH] with the following values

            a
            b
            c
            a
            b
            c
            AC
            AD
            AD
            AE
            AE
            AF
            AF
            AFGTHY
            BE
            BE

            And my Stored Proc goes like this

            **ALTER PROCEDURE sp_Search
            -- Add the parameters for the stored procedure here
            (@SEARCHSTRING VARCHAR(50))
            AS
            BEGIN
            -- SET NOCOUNT ON added to prevent extra result sets from
            -- interfering with SELECT statements.
            SET NOCOUNT ON;

            -- SEARCH WITH ABC COMBINATION
            IF(UPPER(@SEARCHSTRING) = 'ABC')
            
            	BEGIN
            		
            		SELECT \* 
            		FROM TBLSEARCH WHERE RTRIM(LTRIM(NAME)) LIKE '\[A-C\]%'
            
            	END
            
            -- SEARCH WITH DEF COMBINATION
            IF(UPPER(@SEARCHSTRING) = 'DEF')
            
            	BEGIN
            		
            		SELECT \* 
            		FROM TBLSEARCH WHERE 
            
            			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]%' OR
            
            			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]%' OR
            
            			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]%'
            
            	END
            
            -- SEARCH WITH GHI COMBINATION
            IF(UPPER(@SEARCHSTRING) = 'GHI')
            
            	BEGIN
            		
            		SELECT \* 
            		FROM TBLSEARCH WHERE 
            
            			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]\[GHI\]%' OR
            
            			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]\[GHI\]%' OR
            
            			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]\[GHI\]%'
            
            	END
            

            END
            GO**

            N.B.~ The @SEARCHSTRING can assume values either 'ABC' or 'DEF' or 'GHI' [ As your button names ] In my system I am getting the correct output. Please check it and let me know if it is working as per your expectation or not. Regards, Niladri Biswas :)

            Niladri Biswas

            modified on Wednesday, June 24, 2009 8:40 AM

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

            You can do letter groupings in a LIKE clause using SQL2005? cool!

            N 1 Reply Last reply
            0
            • J J4amieC

              You can do letter groupings in a LIKE clause using SQL2005? cool!

              N Offline
              N Offline
              Niladri_Biswas
              wrote on last edited by
              #6

              Yes it is possible. For more details visit this site http://msdn.microsoft.com/en-us/library/aa933232(SQL.80).aspx[^] :)

              Niladri Biswas

              1 Reply Last reply
              0
              • N Niladri_Biswas

                Dear Rupesh, As I don't have MS Access in my system. So I was forced to solve the problem in SQL Server 2005. But the syntax will remain same in both the cases(or may be minor changes which I hope you can do). I have created a table[TBLSEARCH] with the following values

                a
                b
                c
                a
                b
                c
                AC
                AD
                AD
                AE
                AE
                AF
                AF
                AFGTHY
                BE
                BE

                And my Stored Proc goes like this

                **ALTER PROCEDURE sp_Search
                -- Add the parameters for the stored procedure here
                (@SEARCHSTRING VARCHAR(50))
                AS
                BEGIN
                -- SET NOCOUNT ON added to prevent extra result sets from
                -- interfering with SELECT statements.
                SET NOCOUNT ON;

                -- SEARCH WITH ABC COMBINATION
                IF(UPPER(@SEARCHSTRING) = 'ABC')
                
                	BEGIN
                		
                		SELECT \* 
                		FROM TBLSEARCH WHERE RTRIM(LTRIM(NAME)) LIKE '\[A-C\]%'
                
                	END
                
                -- SEARCH WITH DEF COMBINATION
                IF(UPPER(@SEARCHSTRING) = 'DEF')
                
                	BEGIN
                		
                		SELECT \* 
                		FROM TBLSEARCH WHERE 
                
                			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]%' OR
                
                			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]%' OR
                
                			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]%'
                
                	END
                
                -- SEARCH WITH GHI COMBINATION
                IF(UPPER(@SEARCHSTRING) = 'GHI')
                
                	BEGIN
                		
                		SELECT \* 
                		FROM TBLSEARCH WHERE 
                
                			RTRIM(LTRIM(NAME)) LIKE 'A\[DEF\]\[GHI\]%' OR
                
                			RTRIM(LTRIM(NAME)) LIKE 'B\[DEF\]\[GHI\]%' OR
                
                			RTRIM(LTRIM(NAME)) LIKE 'C\[DEF\]\[GHI\]%'
                
                	END
                

                END
                GO**

                N.B.~ The @SEARCHSTRING can assume values either 'ABC' or 'DEF' or 'GHI' [ As your button names ] In my system I am getting the correct output. Please check it and let me know if it is working as per your expectation or not. Regards, Niladri Biswas :)

                Niladri Biswas

                modified on Wednesday, June 24, 2009 8:40 AM

                R Offline
                R Offline
                Rupesh Kumar Swami
                wrote on last edited by
                #7

                first of all many many thanks. 5 from me and sorry for late reply since i am busy with some other project.so i do not reply you This query works well. one more thing whether you have any idea of SQLite. since i just check and run this query in sqlite. but i don't know the syntax which is similar to above syntax (as you suggest)

                Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

                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