Problems with Select statement!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gggram2000
    New Member
    • Nov 2007
    • 97

    Problems with Select statement!

    Is this a proper statement to make if I want to select from Two tables called Guest and Sales so that i can pass those parameters into some labels? For example, I want GuestFirstName to be @GuestFirstName and display in a label.

    Code:
    string sSQL = " SELECT GuestFirstName,GuestLastName,GuestAddress,Country,GuestPhone,GuestEmail,GuestArrivedDate,SaleTotal,InvoiceNumber,SaleItem,SaleType,SaleDiscount,Date,Quantity,SalePrice  FROM Guest, Sales WHERE GuestFirstName,GuestLastName,GuestAddress,Country,GuestPhone,GuestEmail,GuestArrivedDate,SaleTotal,InvoiceNumber,SaleItem,SaleType,SaleDiscount,Date,Quantity,SalePrice = @GuestFirstName,@GuestLastName,@GuestAddress,@Country,@GuestPhone,@GuestEmail,@GuestArrivedDate,@SaleTotal,@InvoiceNumber,@SaleItem,@SaleType,@SaleDiscount,@Date,@Quantity,@SalePrice ";
    Thanks in advance,
    George
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The query looks wrong, and I don't know what this means.
    For example, I want GuestFirstName to be @GuestFirstName and display in a label.
    Are you trying to use SQL variables?
    May I suggest you write a shorter test query first, get that working then expand it to SELECT the fields required.

    Comment

    • gggram2000
      New Member
      • Nov 2007
      • 97

      #3
      Originally posted by code green
      The query looks wrong, and I don't know what this means.
      Are you trying to use SQL variables?
      May I suggest you write a shorter test query first, get that working then expand it to SELECT the fields required.
      Ok, the thing is I'm not quite sure about the syntax
      Code:
      string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
      The Select I know it can't be right because it somehow seems redundant, I want the value i get from the table (In this case: GuestFirstName) be passed into a parameter so i can manipulate it to display on either a textbox, label or comboBox. I have created a class that allows me to have a dataview, therefore i need that parameter to permit the view. I just need to know the functional syntax as to how to change a value so I can use it.

      e.g.
      Code:
      myCommand.Parameters.Add("@GuestFirstName", SqlDbType.VarChar).Value = label.Text;
      Later on I will use this using the class this way:
      [CODE]
      label.DataBindi ngs.Clear();
      label.DataBindi ngs.Add("Text", mydbview, "Guest.GuestFir stName");
      (public string) GuestID = label.Text;
      [\CODE]

      I hope this is clear...

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName
        Code:
        string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
        I can't see where you are defining or reading the value of @GuestFirstName ,
        but this query will return a GuestFirstName from the table Guest that has the value inside @GuestFirstName .
        Don't know why you want that. I see what you mean about redundant.
        But to clarify, the query RETURNS a value from the table.
        Not change a value.
        If you want to read the returned value into a SQL variable you need
        Code:
        string sSQL = " SELECT @GuestFirstName := GuestFirstName FROM Guest WHERE GuestFirstName = 'a value such as id ";
        My VB is a little rusty so I hope this is what you are trying to do

        Comment

        • gggram2000
          New Member
          • Nov 2007
          • 97

          #5
          Originally posted by code green
          The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName
          Code:
          string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
          I can't see where you are defining or reading the value of @GuestFirstName ,
          but this query will return a GuestFirstName from the table Guest that has the value inside @GuestFirstName .
          Don't know why you want that. I see what you mean about redundant.
          But to clarify, the query RETURNS a value from the table.
          Not change a value.
          If you want to read the returned value into a SQL variable you need
          Code:
          string sSQL = " SELECT @GuestFirstName := GuestFirstName FROM Guest WHERE GuestFirstName = 'a value such as id ";
          My VB is a little rusty so I hope this is what you are trying to do
          Yeah I see what you mean when you say u cant see where i'm reading the value, the reason is because I'm using it later on to be displayed in an excel cell. And well I only need to return a value from the table since I'm just using it for a person to view it. Appreciate it.

          Sincerely,
          George

          Comment

          Working...