Archive for the ‘select statement’ Category

Select whether the following statement is always true, sometimes true, or never true?

October 31, 2009 - 9:17 pm 4 Comments

The hypothesis of a statement is the if part.

A. Always
B. Sometimes
C. Never

B

SOL Statement to select only the last row in a table?

October 17, 2009 - 8:21 am 3 Comments

I am working with a database that has an auto number field. I am making an applicaton to update the table so I have to have a way to get the last primary key number in the table and add 1 to it so that I can imput the correct number into the primay key field. I need to know if there is an SQL statement that will just pull the last row from a table. Right now I have a count that runs threw the entire database till it get to the bottom and stores the last autonumber in count then I add one to that and store my new data. The problem is it is slow and right now I dont want to get ride of the auto number filed but eventually I will. So anyone know a SQL statement that will go to the last recored right away?

I don’t think this can be done in a single statement. It can be done in two statements though:

SELECT MAX(your auto number field)

And then use that value in your second SELECT.

What is the MS SQL query(Select Statement) for the following:?

October 11, 2009 - 10:22 am 2 Comments

List all details for all Items where the difference between the Item Cost and the List Price exceeds $1?

ex. Select * from Items where ItemCost - ListPrice > ‘1′

The example is not incorrect I think…..

Select * from Items where (ItemCost - ListPrice) > 1

You use quotes only for strings.

VB: using sql select statement from access database.?

October 5, 2009 - 3:59 pm 2 Comments

How to write a statement that selects records. in that if i click on suppliers name from datacombo, the other details (address, location etc) are shown on the txtbox.

this link is just what you are looking for … enjoy!….

http://www.vbexplorer.com/VBExplorer/wrox/sample1061.asp

USING PUBLISHED REPORT SELECT TWO CEOs WHO HAVE RECENTLY MADE PUBLIC STATEMENt?

October 1, 2009 - 10:03 am 1 Comment

USING PUBLISHED REPORT SELECT TWO CEOs WHO HAVE RECENTLY MADE PUBLIC STATEMENT REGARDING A MAJOR CHANGE IN THEIR FRIM’S STRATEGY.DISCUSS HOW THE SUCCESSFUL IMPLEMENTATION OF SUCH STRATEGIES REQUIRES CHANGES IN FIRM’S PRIMARY AND SUPPORT ACTIVITIES.

Please do your own homework

Select a counterexample to show that the statement is false.?

September 29, 2009 - 9:21 am 2 Comments

Select a counterexample to show that the statement is false. When an odd number is added to the product of two even numbers, the result will be even.

4•5 + 1 = 21. 21 is not even.
4•2 + 3 = 11. 11 is not even.
4•5 + 2 = 22. 22 is even.
3•5 + 4 = 19. 19 is not even.

It’s 4 times 2 plus 3 equals 11. 11 is not even.

Microsoft Access 2003: How can I make the value of a WHERE in SQL SELECT statement depend on a field within…?

September 27, 2009 - 11:15 am 2 Comments

Microsoft Access 2003: How can I make the value of a WHERE in SQL SELECT statement depend on a field within the query?

For example: In XYZ Query, having Field1, Field2, Field3, Field3 has a SQL SELECT * FROM ABC Table WHERE Field1 (from ABC Table) = Field1 (from XYZ Query). I want to make it so that the value in Field1 (ABC Table) will be filtered depending on the value of Field1 (XYZ Query).

Specifically: I have a table named Table1 with fields SNumber and Quantity. The value of the fields are as follows respectively: 001, 10; 001, 15; 001, 30; 002, 25; 003, 35; 004, 5; 004, 15. I have a query named Query1 that shows the total of Table1 with fields SNumber and Total. The value of SNumbers are those the value of SNumbers from Table1 but with duplicates such as 001; 002; 003; 004 only and will show the total of the Quantity from Table1.

I made an expression in Query1, Total (field): (SELECT SUM(Quantity) FROM Table1 WHERE SNumber(*this refers to SNumber of Table1)=How(*The SNumber field from Query1)). I want the query to filter the quantity to sum.

The query should produce this output:
Query1
SNumber——–Total
001—————-55
002—————-25
003—————-35
004—————-20

Based on the data from this table
Table1
SNumber——–Quantity
001—————-10
001—————-15
001—————-30
002—————-25
003—————-35
004—————-5
004—————-15

Please send me a YM at goshenite_2004 for more info.

SELECT SNumber, SUM(Quantity) As Total FROM Table1
GROUP BY SNumber

How to subtract results from two SQL select statement?

September 25, 2009 - 12:18 pm 1 Comment

How will I subtract in SQL? For example:

SELECT SUM(rs_amount_conv)
FROM RS_BALANCES_T
WHERE supp_id = :VAR_SUPP_ID_1 AND period_year = :VAR_YEAR_1 AND rs_tran_type_id = 1

SELECT SUM(rs_amount_conv)
FROM RS_BALANCES_T
WHERE supp_id = :VAR_SUPP_ID_2 AND period_year = :VAR_YEAR_2 AND (rs_tran_type_id = 2 OR rs_cr_dtl_id IS NOT NULL)

I am using Oracle Database 10g,

SELECT SUM(rs_amount_conv) - (SELECT SUM(rs_amount_conv) FROM RS_BALANCES_T
WHERE supp_id = :VAR_SUPP_ID_2 AND period_year = :VAR_YEAR_2 AND (rs_tran_type_id = 2 OR rs_cr_dtl_id IS NOT NULL) )
FROM RS_BALANCES_T
WHERE supp_id = :VAR_SUPP_ID_1 AND period_year = :VAR_YEAR_1 AND rs_tran_type_id = 1

You need to subtract the amount from the first with a subquery

What is wrong with this SQL Select Statement?

September 23, 2009 - 2:25 pm 2 Comments

I am trying to select all the values from a column called "08" in reverse numerical order. When I run the following, every row returned has a value of 8, even though the actual values in the database are numbers like 236, 36, and 5. Why does the following Select statement not return the actual numerical values in the column called "08"? The column called "08" has a field type of INT(08).

$result = mysql_query ("SELECT 08 FROM May08 ORDER BY 08 DESC");

while ($row = mysql_fetch_array ($result)) {

$val=$row['08'];

echo $val;

}

enclose names in ` (backtick) :
SELECT `08` FROM May08 ORDER BY `08` DESC

I need an MS Access Query Select Statement?

September 21, 2009 - 12:09 pm 4 Comments

I am trying to run a promotion listing in MS Access 2007. In a database with employment histories, I need to select all employees’ PREVIOUS job title, before the current one.

I know how to select the most current or last title and I also know how to select the first title, but I don’t know how to select the "second title", or the "third title", or the "previous title" one. Can this be done with a SQL statement or some other way in Access?
This is a basic access database table connected through ODBC (I cannot modify the table design/fields).

Individually, the records are identified by date, for example your first job may be 5/1/08 (also the current job), the one before that, 1/3/07, the one before that 10/15/05 and your first job 7/1/2002 (which is equal to your hire date), the problem is, there is no limit or methodology to WHEN a person can change jobs.

When I am trying to select ALL employees’ previous job (1/3/07 job in the previous example), of the 10,000 or so records in the table, the previous jobs could be ANY date so if I restrict by date (jobs since 1/1/07), I may miss someone who hasn’t had a job change in three years or have multiple records for someone who has changed jobs several times since that date.

I am only concerned with the 1 most recent previous job that each person held, regardless of how long ago or how recent it was, or how many times they have changed jobs.

Hope that helps.

In just about anything but Access You could use a "subquery" in your select statement to do this. http://sqlzoo.net/1a.htm

BUT the "SQL Jet" that Access uses doesn’t recognize subqueries as such… Sooo, You’ll need to have several Queries that tie to each other that dynamically build a "Pick List":

1st Query: Isolate the Current job for each Employee:
GROUP BY Employee, MAX ([Job Date]).

2nd Query: Get the listing of ALL PREVIOUS Jobs by date:
Add both the TABLE and 1st Query, but link them only by Employee. Get 2 columns from the TABLE: Employee, Job Date
In the criteria of Job Date say <[1st Query]![MaxofJob Date]

3rd Query:
Isolate the last job in 2nd Query by Date:
GROUP BY Employee, Max of Job Date

4th Query:
Add both 3rd Query & the TABLE
Link 3rd Query to the TABLE by Employee and Max of Job Date…Select the columns You need…

Any additional questions would be best directed to a Forum, since YA doesn’t allow for the back & forth that may be needed to tweak this set-up or walk You through it…