Query and Sub-Queries

I have a SELECT statement that has two sub queries in it.  The 'where' 
clause in the main query filters a TRADE_DATE field, for example: ...... 
where TRADE_DT  >= '2003/01/01' and TRADE_DT  <= '2003/01/31'.

Since I only have one date field(TRADE_DATE), I want the sub-query to query 
where TRADE_DT  <= '2003/01/31'.  But its not working.  I have to hard code 
the '2003/01/31'.  Now I know I can make a dynamic view in VB, but an ideas 
of how  I can do it in SQL?  Here's my statement:

    (select sum(COMMISSION) from Trade  where SOFT_TRADE = 1 
    TRADE_DT  >= '2003/01/01' and TRADE_DT  <= '2003/01/31') AS 
    (select sum(COMMISSION) from Trade  where SOFT_TRADE = 1 
     TRADE_DT  <= '2003/01/31' ) AS SOFT_COMMISSIONS_TO_DATE
    from dbo.Trade T,dbo.Broker B where SOFT_ELIGIBLE in(1,-1) and 
T.BROKER_SEQ_NO = 6000031
    and T.TRADE_DT  >= '2003/01/01' and T.TRADE_DT <= '2003/01/31'
3/21/2003 5:38:13 PM
sybase.ase.general 8655 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 24


Similar Artilces:

Query and ?sub query??
Hi there,I hope this is the right place to ask this question.I have two Access tables (tblUsers and tblMessages) to use in datagrid. tblMessages has two relations with tblUsers - the UserID field and the SenderID field, both of which are one-to-many relationship. When the user goes to the inbox, the data selected needs to do the following:1) pull out the messages with the UserID that matches the current user id number.2) since it needs to display the username of the person who sent the message, I need to pull out 'username' from tblUsers where it matches the SenderID. Storing the userna...

Query about Queries
Hello all, As a relatively new user to Sybase I am hoping someone can point me in the right direction. We are getting ready to go live with our database and I am wondering what types of queries I should be running for system performance purposes. If anyone has any suggestions they would be more than appreciated. Thanks in advance, Jerry ...

How to Query A Query
I have been trying to build a crosstab report that reports everydate within a selected range across the top and specific row information. 7/1 7/2 7/3 . . . Name Detail1 Detail2 Detail3 Name Detail1 What I get as output is only the dates that contain information in the rows. I can get the information I need by using a query within a query (nested). Can a nested query be done in Informaker 5? What about version 6 or 7? Thanks for your help Convert your SQL to syntax, and you can write anything you want. So if your DB support...

Query a Query
I have a result set in a query. Is it possible to query this query? (no specific SQL dialect, can it be done generically?) Petros -- PETROS GAVRIELIDES wrote: > I have a result set in a query. > Is it possible to query this query? > > (no specific SQL dialect, can it be done generically?) There is a generic answer to your question: Yes, there is a construct called a sub-query that allows you, in 1 SQL statement, to query from a query. But, generically speaking, not all DB engines support this construct. For instance, Firebird only added it just over a y...

How to query a query...
I'm working on converting an Access DB that I created into an ASP.NET application (and attempting to learn ASP at the same time...). One of my queries was very complex and required running a different query first, and then working off of that one. Any suggestions on the best way to do this in ASP? The following is a sample of code I'm using so you can see the type of data-binding I'm using. Thanks for the help! myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +"Data Source=" + Server.MapPath("/EquipmentCheckout.mdb")) strS...

Query Effeciency, sub query
is it more efficient to make multiple parameters or to use sub queries, for instance i have a database of contacts, and i would like to narrow it down to the people who have not been called yet, and then use some other criteria also would it be best to do a subquery to get the results of the people who have not been called, then off of that sub query run the main query of which state i would like to call? or is there an even better way that i may not know. i am a beginner of efficiency in SQL, i can run dirty not so efficient queries pretty easy, but i have not gotten to deep into e...

Which one is faster? Sub-query in select clause or sub-query in from clause
I have a query which contain a sub-query in the select statement: SELECT distinct users.familyname, users.givenname, users.currentPID, (SELECT code_orgstructure.description FROM users, code_orgstructure,ser_orgs WHERE user_orgs.userid = users.userid AND user_orgs.domaintype = 'S' AND user_orgs.orgsequence = 2 AND user_orgs.orgid = code_orgstructure.orgid ) , userinfo.b_address1, userinfo.b_address2,userinfo.b_city, userinfo.b_province_state,userinfo.b_country, userinfo.b_postalcode FROM users, transcript, userinfo WHERE users.userid = transcript.userid AND ...

Query Within A Query?
I have a table that looks kinda like thisTag         Info              SignOutDate1             Hi                   09/03/20051             Hi                   09/02/20051   &n...

Querying a Queried result...
Hi, is there such a thing as querying a queried result? Example, query 1 produces Result A. Result A's table is stored 'somewhere' to be queried by query 2 which produces Result B If there is, could you kindly direct me to a website with the appropiate article on this topic? Thanks, -Gabian- Yes there is, querying a View is querying a query rewrite. Send me an email the address is in my profile I will send you a Views tutorial I wrote a while back and run a search for query results from View in your BOL(books online) for code samples. Hope this helps. Kind regards, ...

query runs fine in Query Analyser but not the Query Debugger
I'm running a query, actually its an insert that works when using the TSQL below. However when I try to use the debugger to step through and using the exact same values as those below I get the following error: [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification Its Killing me because everything else works, but this. Can somebody help. DECLARE @NoteID INT,-- NULL OUTPUT, @Note_Description NVARCHAR(3000),-- = NULL, @Date DateTime,-- = NULL OUTPUT, @ByWho NVARCHAR(30),-- = NULL, @FK_Action_Performed NVARCHAR(40),...

SQLite query and AS in query
This is my code. {code} q := TSQLQuery.Create(nil); try q.SQLConnection := MainForm.sqlite1; q.SQL.Text := sql; q.Open; finally q.Free; end; {code} And this is my SQL select id as _id, name, note as description from notes q.Fields[0].FieldName is id, it should be _id q.Fields[2].FieldName is note, it should be description Is this normal or am I missing something Grega This is frustrating. I can't work at all. http://pretty-software.com/images/xe4.jpg Edited by: grega loboda on Jun 4, 2013 1:40 AM http://stackoverflow.com/question...

Query Plan Query
We have a sql query that is causing a few issues in terms of performance as the optimisor is choosing to table scan where an index will certainly yield significant gains. As proven when snapshotting the query and adding an index hint manually. Unfortunatley since the query is dynamically created by a 3rd party application, we are unable to influence this with index hints and are dependant on the optimiser. The table that is table scanning is partitioned (has also hust been repartitioned to address a slight inbalance across partitions) and has 7.6M records. It has been recently r...

Query to Save Queries
Save SQL Statements in the Host SQL MENU??? Hi there, I want to add items to the pencil menu in the Host SQL page. Eg. "Save SQL Query". Could someone point me in the right direction on how to populate the pencil menus. Thanks in advance. If your interested read on : So the idea is to make the currently "empty" pencil menu contain a list of queries, hosts/DnnCommunity can click on & execute, rather than typing them in each time. ''in the page load of admin/portal/sql.ascx.vb ln: 57 I want to add this line of code If Len(Request.Params(&quo...

Query a query in linq
Hi, I have some code that gets some results:var GlobalTable = from p as db.table                             select p; Now I want to run a query in link on the results stored in GlobalTable. Whats the best way to do this? keepin' it real in the ATX. Exactly the way you ran the first query: var GlobalTableSubset = from gt as GlobalTable                        ...

Web resources about - Query and Sub-Queries - sybase.ase.general

Resources last updated: 1/17/2016 2:24:20 PM