473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.

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
Dec 27 '07 #1
4 1179
code green
1,726 Expert 1GB
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.
Dec 28 '07 #2
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...
Dec 28 '07 #3
code green
1,726 Expert 1GB
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
Dec 28 '07 #4
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
Dec 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: steve stevo | last post by:
strSearch is a dynamically created search string Copy of select statement below sql = "SELECT Master.Master_Key,Master.First_App,Original_Info_Date,Last_Info_Date,Area.Ar ea_Name AS...
3
by: bjam | last post by:
Help! The apply-templates function is not currently allowing me to select a specific template... eventhough I tried putting a select statement, it does not seem to work??? Can someone help show...
4
by: ree32 | last post by:
I know when you are using group by functions you have to include all the columns in the GROUP BY clause. But what I am having problems when using a case statement to determine whether to sum of...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
2
by: MC | last post by:
Hi to all, I'm working with DB2 on iSeries V5R3 I would like to know if this kind of SQL statement is possible : select col1, count(col2) from TABLE where col2 in (select1 union select2). ...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
6
by: Norton | last post by:
When i try to use OleDbDataAdapter's QueryBuilder, when i type some SQL Statement "Select Top X .....", it works and display the correct result, however i cannot generate the select statement...
10
by: RainerF | last post by:
Hi Folks, My Problem is: My SQL Statement Structure: SELECT TABLEA.FIELDA, TABLEA.FIELDB, TABLEA.FIELDC, TABLEA.FIELDD,
6
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I am running a simple query using VB (This isnt a VB Question, dont worry!) on SQL Server Compact. I have the query below being created, and then added to if a flower location doesn't...
1
by: ProgrammingStudent | last post by:
I have 2 tables: Customer Table -CustomerID -CustomerName -CustomerState Invoice Table -InvoiceID -CustomerID
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.