Connecting Tech Pros Worldwide Forums | Help | Site Map

Problems with Select statement!

Member
 
Join Date: Nov 2007
Location: Belize City, Belize
Posts: 97
#1: Dec 27 '07
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.

Expand|Select|Wrap|Line Numbers
  1. 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 ";
  2.  
  3.  
Thanks in advance,
George

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#2: Dec 28 '07

re: Problems with Select statement!


The query looks wrong, and I don't know what this means.
Quote:
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.
Member
 
Join Date: Nov 2007
Location: Belize City, Belize
Posts: 97
#3: Dec 28 '07

re: Problems with Select statement!


Quote:

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
Expand|Select|Wrap|Line Numbers
  1. string sSQL = " SELECT GuestFirstName FROM Guest WHERE GuestFirstName = @GuestFirstName ";
  2.  
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.
Expand|Select|Wrap|Line Numbers
  1. myCommand.Parameters.Add("@GuestFirstName", SqlDbType.VarChar).Value = label.Text;
  2.  
Later on I will use this using the class this way:
[code]
label.DataBindings.Clear();
label.DataBindings.Add("Text", mydbview, "Guest.GuestFirstName");
(public string) GuestID = label.Text;
[\CODE]

I hope this is clear...
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#4: Dec 28 '07

re: Problems with Select statement!


The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. 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
Member
 
Join Date: Nov 2007
Location: Belize City, Belize
Posts: 97
#5: Dec 28 '07

re: Problems with Select statement!


Quote:

Originally Posted by code green

The below syntax is correct, assuming you want to use a user-defined variable @GuestFirstName

Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. 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
Reply