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. Test sol

Test sol

Scheduled Pinned Locked Moved Database
database
7 Posts 4 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.
  • S Offline
    S Offline
    Stephen Holdorf
    wrote on last edited by
    #1

    I have a SQL query that is returning

    P Richard DeemingR L 3 Replies Last reply
    0
    • S Stephen Holdorf

      I have a SQL query that is returning

      P Online
      P Online
      PIEBALDconsult
      wrote on last edited by
      #2

      You probably have an operator-precedence problem due to combining OR with AND -- I can never get it right myself, so I always use parentheses. I also recommend not using sub-queries, especially with IN -- try a JOIN instead.

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        You probably have an operator-precedence problem due to combining OR with AND -- I can never get it right myself, so I always use parentheses. I also recommend not using sub-queries, especially with IN -- try a JOIN instead.

        S Offline
        S Offline
        Stephen Holdorf
        wrote on last edited by
        #3

        The only problem I see is how do I add the user and rights tables in to the query? There are no keys to access those tables.

        S 1 Reply Last reply
        0
        • S Stephen Holdorf

          I have a SQL query that is returning

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Try something like this:

          SELECT DISTINCT
          dw.we_System_Key,
          w.we_System
          FROM
          dod
          INNER JOIN do_we_systems dw on d.dod = dw.dod
          INNER JOIN lkup_we_systems w on dw.we_System_Key = w.we_System_Key
          WHERE
          dw.is_deleted = 0
          AND
          (
          w.we_system != ''
          OR
          EXISTS
          (
          SELECT 1
          FROM users_rights ur
          INNER JOIN rights r ON r.rights_key = ur.rights_key
          INNER JOIN users usr ON usr.username = ur.username
          WHERE usr.username = 'RHale1'
          AND r.rights_code = 'Non-Standard Test'
          )
          )
          ORDER BY
          w.we_system
          ;


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • S Stephen Holdorf

            I have a SQL query that is returning

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            holdorf wrote:

            I have a SQL query that is returning

            From where? This looks weird like this; where did the rest of the question go?

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            1 Reply Last reply
            0
            • S Stephen Holdorf

              The only problem I see is how do I add the user and rights tables in to the query? There are no keys to access those tables.

              S Offline
              S Offline
              Stephen Holdorf
              wrote on last edited by
              #6

              I know there are a lot of posts but I finally understand and did what I was told to do. I broke the query up with parameters and I am still getting the security error. My code is below the with the parameters removed from the hard coded string, the calling code, and the implementing code: The 3 classes with the SQL w/ with the parameters broken out, the calling code, and the implementing code: Class with the parameters broken out:

              public class MyParam
              {
              public string name { get; set; }
              public string value { get; set; }
              }
              ///
              /// Summary description for QueryContainer SGH
              ///
              public class QueryContainer
              {

                  string \_query;
              
                  public List parameterList = new List(); 
              
                  public QueryContainer(string query) { \_query = query; }
              
                  public string Query
                  {
                      get
                      {
                          return \_query;
                      }
              
                      set { \_query = value;  }
                  }
              }
              

              The calling code:

                  public int GetAccountSortByAccountCode(int account)
                  {
                      QueryContainer Instance = new QueryContainer("SELECT ac\_sort\_order FROM lkup\_account\_codes where ac\_code = [@account](http://www.codeproject.com/Members/account)");
              
                      MyParam myParam = new MyParam();
              
                      myParam.name = "@account";
                      myParam.value = account.ToString();
              
                      Instance.parameterList.Add(myParam);
              
                      return Convert.ToInt32(ExecuteScaler(Instance, 1));
                  } 
              

              The implementing code:

                          if (\_connection == null || \_connection.State == ConnectionState.Closed)
                          {
                              OpenConnection();
                          }
              
                          DbCommand command = \_provider.CreateCommand();
                          command.Connection = \_connection;
                          {
                              command.CommandText = Instance.Query;
                              command.CommandType = CommandType.Text;
              
                              foreach (var p in Instance.parameterList)
                              {
                                  SqlParameter param = new SqlParameter(p.name, p.value);
                                  command.Parameters.Add(param);
                              }
              
                              if (\_useTransaction) { command.Transaction = \_transaction; }
              
                              try
                              {
                                  returnValue = command.ExecuteScalar();
              
              S 1 Reply Last reply
              0
              • S Stephen Holdorf

                I know there are a lot of posts but I finally understand and did what I was told to do. I broke the query up with parameters and I am still getting the security error. My code is below the with the parameters removed from the hard coded string, the calling code, and the implementing code: The 3 classes with the SQL w/ with the parameters broken out, the calling code, and the implementing code: Class with the parameters broken out:

                public class MyParam
                {
                public string name { get; set; }
                public string value { get; set; }
                }
                ///
                /// Summary description for QueryContainer SGH
                ///
                public class QueryContainer
                {

                    string \_query;
                
                    public List parameterList = new List(); 
                
                    public QueryContainer(string query) { \_query = query; }
                
                    public string Query
                    {
                        get
                        {
                            return \_query;
                        }
                
                        set { \_query = value;  }
                    }
                }
                

                The calling code:

                    public int GetAccountSortByAccountCode(int account)
                    {
                        QueryContainer Instance = new QueryContainer("SELECT ac\_sort\_order FROM lkup\_account\_codes where ac\_code = [@account](http://www.codeproject.com/Members/account)");
                
                        MyParam myParam = new MyParam();
                
                        myParam.name = "@account";
                        myParam.value = account.ToString();
                
                        Instance.parameterList.Add(myParam);
                
                        return Convert.ToInt32(ExecuteScaler(Instance, 1));
                    } 
                

                The implementing code:

                            if (\_connection == null || \_connection.State == ConnectionState.Closed)
                            {
                                OpenConnection();
                            }
                
                            DbCommand command = \_provider.CreateCommand();
                            command.Connection = \_connection;
                            {
                                command.CommandText = Instance.Query;
                                command.CommandType = CommandType.Text;
                
                                foreach (var p in Instance.parameterList)
                                {
                                    SqlParameter param = new SqlParameter(p.name, p.value);
                                    command.Parameters.Add(param);
                                }
                
                                if (\_useTransaction) { command.Transaction = \_transaction; }
                
                                try
                                {
                                    returnValue = command.ExecuteScalar();
                
                S Offline
                S Offline
                Stephen Holdorf
                wrote on last edited by
                #7

                I know there are a lot of posts but I finally understand and did what I was told to do. I broke the query up with parameters and I am still getting the security error. My code is below the with the parameters removed from the hard coded string, the calling code, and the implementing code: The 3 classes with the SQL w/ with the parameters broken out, the calling code, and the implementing code: Class with the parameters broken out:

                public class MyParam
                {
                public string name { get; set; }
                public string value { get; set; }
                }
                /// /// Summary description for QueryContainer SGH
                ///
                public class QueryContainer
                {

                    string \_query;
                
                    public List parameterList = new List(); 
                
                    public QueryContainer(string query) { \_query = query; }
                
                    public string Query
                    {
                        get
                        {
                            return \_query;
                        }
                
                        set { \_query = value;  }
                    }
                }
                

                The calling code:

                    public int GetAccountSortByAccountCode(int account)
                    {
                        QueryContainer Instance = new QueryContainer("SELECT ac\_sort\_order FROM lkup\_account\_codes where ac\_code = [@account](http://www.codeproject.com/Members/account)");
                
                        MyParam myParam = new MyParam();
                
                        myParam.name = "@account";
                        myParam.value = account.ToString();
                
                        Instance.parameterList.Add(myParam);
                
                        return Convert.ToInt32(ExecuteScaler(Instance, 1));
                    } 
                

                The implementing code:

                            if (\_connection == null || \_connection.State == ConnectionState.Closed)
                            {
                                OpenConnection();
                            }
                
                            DbCommand command = \_provider.CreateCommand();
                            command.Connection = \_connection;
                            {
                                command.CommandText = Instance.Query;
                                command.CommandType = CommandType.Text;
                
                                foreach (var p in Instance.parameterList)
                                {
                                    SqlParameter param = new SqlParameter(p.name, p.value);
                                    command.Parameters.Add(param);
                                }
                
                                if (\_useTransaction) { command.Transaction = \_transaction; }
                
                                try
                                {
                                    returnValue = command.ExecuteScalar();
                                }
                
                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