Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

SQL Expression Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SQL Expression Help

    I'm actually creating a report in SQL Report Builder 3.0, so I am not even sure if this question I allowed in here or not, but I figured I would give it a shot. I am very new at SQL so bear with me .............

    I have a database that lists data related to several different police departments, but they are identified by a 4-digit code rather than by their name. For most agencies that is no problem, but some have more than one code, and I want the user to be able to filter the reports by a "user friendly" agency name rather than by the code. In the example below, I have the report builder filter parameter set to one specific agency and code, and it works fine.
    Screen Shot 11-27-17 at 06.43 PM.JPG

    Obviously I am filtering this report to a specific agency whose code in the database table is "0210." This works perfectly, but unfortunately this particular agency actually has records with two "agency codes." Some records are 0210 and some are 0211. As such, I want to write an expression that basically says Berwyn Heights PD = 0210 Or 0211, but that apparently is not the correct way to write it because it fails. (I also tried it as Berwyn Heights PD = "0210" Or "0211", along with Berwyn Heights PD = "0210" .or. "0211", but those didn't work either.)
    Screen Shot 11-27-17 at 06.57 PM.JPG


    I've searched the internet until my fingers are sore, and I can't find an answer, so I am wondering if anyone here knows the correct way to write this SQL expression?


    Thanks,
    Rich
    Attached Files
    Sergeant Richard Hartnett
    Hyattsville City Police Department
    Maryland

    #2
    Re: SQL Expression Help

    Dear Rich,

    From a SQL perspective, the best way to handle this is to create an intermediate table in SQL server that holds the values. The code column would be the primary key column and the 2nd column the department name. Then create a view joining the main table with the intermediate table on the code column. Optionally create a foreign key in the main table using the code column from the intermediate table as the source. To get the filtered records, run a SELECT statement on the department name column of the view (i.e. SELECT * FROM MyView WHERE DepartName = 'Berwyn Heights'). This will return all records with codes assigned to Berwyn Heights in the intermediate table.

    John

    ps:

    Assuming that the report already has a defined filter that accepts a return of the 'code' values to fill the parameter, click the 'run a query' radio button, use the above select statement but instead of the asterick use the column name for the 'code'. (i.e. SELECT code FROM MyView WHERE DepartName = 'Berwyn Heights')
    Last edited by elkton_john; November 27, 2017, 10:34 PM. Reason: added ps

    Comment


      #3
      Re: SQL Expression Help

      I don't have access to the data tables other than to query the data through SSRS Report Builder for creating reports. The actual database belongs to another agency so I can't edit it or alter it in any way, which includes building any tables.

      I thought it was a simple as an expression, but I guess not.
      Attached Files
      Last edited by Rich Hartnett; November 28, 2017, 02:54 AM.
      Sergeant Richard Hartnett
      Hyattsville City Police Department
      Maryland

      Comment


        #4
        Re: SQL Expression Help

        I thought it was a simple as an expression, but I guess not.
        not that difficult.not using sql server nor report builder, just curious, to play with ( time on hand this morning).

        go to the query builder and change the query to
        SELECT ..... WHERE agency_code IN (@agency_code) -(meaning - change the equal sign to IN and fill in proper agency code field name)
        then on the parameter properties select general and check allow multiple values
        then run the report
        at the parameter drop-down enter one agency code click return and then enter the second one. run the report.
        hopefully it will work for you.
        Last edited by GGandhi; November 28, 2017, 09:25 AM. Reason: corrected parameter definition
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: SQL Expression Help

          Thanks but I'm not trying to run a report with multiple agencies, I want to report for a single agency, but that single agency may have multiple "codes" associated with it. In this particular data table they are called "BeatNames."

          Maybe this will make it clearer, as I know I'm probably not explaining it correctly. If you look at the screen shot below, you will see that I set "Berwyn Heights PD" as the lookup list label twice, and each one searches for all records with a particular "BeatName" code of either 0210 or 0211. That works fine if the user selects either one, but what I want is for the user to only have one lookup option for Berwyn Heights, and have it look for either 0210 or 0211 at the same time.

          ScreenShot013.jpg


          I was hoping that could be done in the expression builder with an "OR" statement. Something like "=0210 OR 0211."

          ScreenShot015.jpg

          ScreenShot014.jpg
          Sergeant Richard Hartnett
          Hyattsville City Police Department
          Maryland

          Comment


            #6
            Re: SQL Expression Help

            i will have to test tonight, since the report builder is at home.
            can you post imaginary data at least three or four records and show what needs to be filtered. ( or desired result)
            i can build that table into and try filtering that table.
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: SQL Expression Help

              Thank you very much for trying to help me with this.

              I have attached a small file with about 20 records.

              You'll notice that one field is called "BeatName." That is the field I need to filter records on, but my problem is that one single agency can be associated with several "BeatNames."

              For example, the Berwyn Heights Police Department handles calls for service in the 0210 or 0211 beat area. As such, when a user wants to filter a report by the Berwyn Heights PD (for example), the report would need to filter all calls with a BeatName of 0210 or 0211 in the record. The thing is that I can easily create a parameter filter right now that says "Berwyn Heights PD = "0210" or another one that says "Berwyn Heights PD = "0211," but that requires the user to perform two separate searches.

              What I am trying to do is create an parameter expression on the BeatName field that says Berwyn Heights PD = "0210 OR "0211"

              In Alpha 5 that type of expression would look something like this: BeatName = "0210" .or. BeatName = "0211" but apparently that doesn't work in SQL.




              CFS Test Data.zip
              Sergeant Richard Hartnett
              Hyattsville City Police Department
              Maryland

              Comment


                #8
                Re: SQL Expression Help

                Rich,

                I understand what you are trying to do. The report definition has a query filter that uses the parameters that can then be filled at run-time. Do you have access to that filter? If so, I suggest that you copy it and post it here. Also, do you have permission to modify the filter?

                John

                Comment


                  #9
                  Re: SQL Expression Help

                  i see the numbers (without the leading 0 ) but how would any one know those two are associated?
                  (for that matter, it may not be important at all, you just want the logic?)
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                    #10
                    Re: SQL Expression Help

                    This reply is to both of you. (John & GGhandi)

                    John I think this is what you are talking about, and if so, yes that is where I am trying to create the expression. If you look at the first and second pics, you will see that as a test, I created two parameter filters, one to search for records with "0210" and a different one to search for "0211," as both of them are related to the same police department (Berwyn Heights).
                    Screen Shot 11-28-17 at 04.11 PM.JPG Screen Shot 11-28-17 at 04.11 PM 001.JPG

                    But I don't want the user to have to search twice, so in the pics below, I have only one parameter filter, and in the expression section, I have what I thought was the correct expression to search by both "0210" and "0211," but it gives me an error.
                    Screen Shot 11-28-17 at 04.19 PM.JPG Screen Shot 11-28-17 at 04.12 PM.JPG


                    GGhandi, I know the data I sent you only shows "210" or "211" and I'm not sure why, as the leading zero is definitely in the database records, but for testing I'm sure you can use it as is.
                    Last edited by Rich Hartnett; November 28, 2017, 05:30 PM.
                    Sergeant Richard Hartnett
                    Hyattsville City Police Department
                    Maryland

                    Comment


                      #11
                      Re: SQL Expression Help

                      sorry, i keep going to my steps over and over again.
                      i tested with your data and added a parameter to allow multiple values and called the parameter select beat
                      then entered 210 and 211 the report seems to come out alright.
                      if something pops up i will let you know.
                      thanks for reading

                      gandhi

                      version 11 3381 - 4096
                      mysql backend
                      http://www.alphawebprogramming.blogspot.com
                      [email protected]
                      Skype:[email protected]
                      1 914 924 5171

                      Comment


                        #12
                        Re: SQL Expression Help

                        I'm confused, did you say you were able to make it work with two different Beat numbers??
                        Sergeant Richard Hartnett
                        Hyattsville City Police Department
                        Maryland

                        Comment


                          #13
                          Re: SQL Expression Help

                          yes, i will post a screencast soon
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          [email protected]
                          Skype:[email protected]
                          1 914 924 5171

                          Comment


                            #14
                            Re: SQL Expression Help

                            https://www.screencast.com/t/dEJUMdkN

                            okay here is the start, I will work on the report itself to show how it looks when finalized, or you can beautify it.

                            here is a second attempt:
                            https://www.screencast.com/t/x0zqtGLz6hc


                            since I do not use my expertise in fashioning the report is rudimentary. should be able to do better given time.
                            Last edited by GGandhi; November 28, 2017, 10:14 PM.
                            thanks for reading

                            gandhi

                            version 11 3381 - 4096
                            mysql backend
                            http://www.alphawebprogramming.blogspot.com
                            [email protected]
                            Skype:[email protected]
                            1 914 924 5171

                            Comment


                              #15
                              Re: SQL Expression Help

                              Take a look at this. It will help show what my ultimate goal is.

                              Thanks

                              Report_Builder_Demo_(11-28-17).swf
                              Sergeant Richard Hartnett
                              Hyattsville City Police Department
                              Maryland

                              Comment

                              Working...
                              X