Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Use Calculated Field In Same Query


Right now I have one view that grabs records and sums up related records etc.... and returns a result. So basically it has the ID number and the number I calculated. THen I have another view that takes that number and performs calculations on it into three different columns. Is there any way to make these two view into one without a lot of repetative statements? Here is an example:

SELECT (tblTest.Quantity * tblTest.Price) as SubTotal, SubTotal * 1.06 as Total

Obviously that doesn't work, but what could I do to get that basic thing to work?

Thanks!




View Complete Forum Thread with Replies

Related Forum Messages:
Referencing A Calculated Field In A Query
I would have a question, if it is possible to reference a calculated field in T-SQL query. The following expression does not work in SQLExpress 2005

SELECT Qty, UnitPrice, Tax, Qty*UnitPrice as Expr1, Expr1*(1.0 + Tax) AS Expr2

This problem has occurred after upsizing to SQLExpress from Access XP/Jet Engine. Since Access does not have any issue with the expression above, the SQLExpress does not even accept it.

The only way how to avoid the issue in the SQLExpress seems probably to be

- Duplicate some calculations (i.e. expand every expression with duplicating some mathematic operations with some performance loss)

- Utilize computed columns if possible (no idea on performance impact here)

Am I right or is there any other way how to reference a calculated field?

Any suggestion is greatly welcomed! Thanks in advance.

View Replies !
Index In Calculated Field From A Ntext Field
For some reasons I have to use a ntext field for both small strings like "10" and large binalry files.

I need to sort the field to some extend to present the small strings on a sorted nice way - answers to " What country are you from" etc.

To trick the sorting I use a calculated field:

ORDER BY RSort - where Rsort is:

convert(varchar(4), RD.response) as RSort

It works but put a high load on the SQL server when the number of responses increases.

I though of making a non clustered index based on the calculated field, but is not sure that it will work as intended.

What do I do. The last thing would be to change the ntext to vchar(3800) or something like that. :confused:

View Replies !
Calculated Field
 HiI am using Management Studio with SQL Server 2005 Express. I am trying to use the Calculated Column Specification by entering a formula.Every attempt results in the same error 'Error Validating the formula'Lets say I have 3 columns a,b, and cI wish to put a formula into c so that it becomes a/bCan anyone either help me with the syntax or point me a resource. I have googled without success. There seems to little or nothing out there on this topic.Thanks,Bill 

View Replies !
Calculated Field
I am a newbie to SQL Server using SQL Server 2000.

I am trying to use a calculated field in a table, what I want is for the result to be shown as an integer (int)?
However the fields that I base the calculation on are of the type (money), and the calculted field although giving me the correct result makes the field of type (money).

The fields that I am basing the calculation on are:-

ColumnName Type Size Allow Nulls
PurchasePrice money 8 0
LoanSize money 8 0



this is the code for the calculated field


([loansize] / [PurchasePrice] * 100)


and this is the description of the calculated field that is forced in the designer



ColumnName Type Size Allow Nulls
LTV money 8 1



and the designer does not allow me to change the type.

I would be grateful of any pointers

Regards

Tony

View Replies !
Calculated Field
 

This may be an extremely simple question, but I am trying to combine two text fields (last name, comma, space and first name) into a new field that can be used as a GROUP in my report.

 

What is the simplest way to accomplish this?

View Replies !
Calculated Field (GPA)
I have a table and I need to have a calculated field which calculates GPA based on the letter grade they have, and only those grades that have subject as CHEM or BIO.
 
here is a sample table:
 
 






Term

ID

LastName

FirstName

CRN

Subject

LetterGrade

Calc GPA


20072

1

Doe

John

1234

CHEM

B

 


20072

1

Doe

John

3214

BIO

A

 


20072

1

Doe

John

4321

LAW

B

 


20072

2

Bauer

Jack

1234

CHEM

A

 


20072

2

Bauer

Jack

3214

BIO

C

 


20072

2

Bauer

Jack

5467

FIN

B

 

 
A = 4.0
B = 3.0
C = 2.0
D = 1.0
 

View Replies !
Calculated Field
I have the following fields in table A:

GL_ID|GL_Name_VC| Amount |Period_TI|Year_SI
===================================================
1000|liability | -10,000.00 | 08 | 2005
===================================================
1001| asset | 20,000.00 | 08 | 2005
===================================================
1000|liability | -9,000.00 | 09 | 2005

the fields above have the following datatype:

Fields | Datatype
===================================
GL_ID | Integer
GL_Name_VC | Variable Character
Amount | Integer
Period_TI | TinyInteger
Year_SI | SmallInteger


The above database is running on Microsoft SQL Server 2000 and i would like to query
for a report that looks something as below:

Description Amount
asset 20,000.00
liability (10,000.00)
===========
Net Asset 10,000.00
===========

The above report would list 2 columns as Description & Amount, next it would sort the Description
column by GL_ID, next by Year 2005 & lastly by Period 08, with a net figure of asset minus liability.

Guys, hope someone out there can help me with the sql command for the above report?

View Replies !
Calculated Field In SQL 2000
I need a calculated field C with several CASES. If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50 If (field A is hourly and field B is NULL then C= 850I don't know sql server 2000 well enough to create this query.thanksMilton

View Replies !
AttribDescription As Calculated Field
Hiin T-SQL,(how) is it possible to concatenate 3 (varchar) fields into one; eitherin a SQL query or through a calculated field (or using a view, ifanybody can explain to me how to use views), according to the followingrules:{first 30 chars of Trim(AttributeVal1)if resulting string<30 chars append", " & first 30 chars of Trim(AttributeVal2)if resulting string<30 chars append", " & first 30 chars of Trim(AttributeVal3)}=> define as new field StockItemDescriptionideally I would like SQL Server to do this processing rather thanbuilding all these answer strings on the client side.tiaAxel

View Replies !
How To Generate Calculated Field
I need to run a data report that will query an Access_Table that has thefollowing Project info:My Form has a command_button with the following code:Private Sub Command1_Click()Set db = New Connectiondb.CursorLocation = adUseClientdb.Open "PROVIDER=MSDataShape;DataPROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &"Access_Table.mdb;"Set adoAge = New RecordsetadoAge.Open "SELECT CustomerName, OrderNo, Invoice_Date,IIf([Invoice_Date]<Now()-30 And[Invoice_DATE]>Now()-60,[Invoice_Amount],"") AS Greaterthan30,IIf([Invoice_Date]<Now()-60,[Invoice_Amount],"") AS Greaterthan60 FROMCust WHERE [Invoice_Date]< Now()-30", db, adOpenStatic, adLockOptimisticSet DataReport1.DataSource = adoAgeDataReport1.ShowEnd SubMy DataReport1 has the following RptTextbox:RptTextbox Datafield1 CustomerName2 OrderNo3 Invoice_Date4 Greaterthan305 Greaterthan60Problem arise when trying to display the above report that has an errormessage that says "Datafield Greaterthan30 not found"Is this an SQL Query limitation where Invoice_Date Datafield can only bequeried once & if we have more than one Datafieldwith the same fieldname (Invoice_Date) within the same Data report,thereport will fail to run? Should there be one moreNew Recordset to hold a second Datafield (Invoice_Date)?can anyone help? ThanksFrom:Cady Steldyn*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View Replies !
Calculated Field In SQL Server 6.5
I am used to working in MS Access where you can return a value as in:
[date1]-[date2]=X

It will calculate that value provided "date1" and "date2" are fields in the recordset. One calc for each record.
I am getting an error message in SQL Server saying that neither "date1" nor "date2" are not contained in an aggregate function and there is no "group by" clause.
In Access this would not be a problem.
Can you help?
Thank you.

View Replies !
Calculated Field In A Csv File
 

I have a fairly simple SQL code that includes a calculated field (date difference) in Oracle. I am bring the data in a csv format, and its giving me nothing for that calculation. I checked the results in TOAD and they look fine. I know, i am missing something for the format but have tried everything.
I am new to this so any help is appreciated.
 
Thanks

 
select rpt.emc_last_run_date "Report Run Date",

(rpt.EMC_ACCEPT_DATE_TIME - rpt.EMC_QUEUED_DATE_TIME * 24 * 60) "Time To Accept(mins)"

View Replies !
Filtering A Calculated Field
Hi everyone, I created a calculated field  (=Fields!RUN_RATE.Value / Fields!STANDARD.Value)
this field gives me my % of Standard field. I want to be able to display anything over 200%. I tried filtering it as a group filter, but when it runs it first shows everythin ok, I put my dates (parameter), right when I click to view report, it gives me an error displaying:
 
An error has occured during report processing.
The processing of filter expression for the table 'table1' cannot be performed. The comparison failed. Please check the data type returned by filter expression.
 
Any ideas, comments, remarks?????
 
Thanks,
Abner

View Replies !
Calculated Field Issue
 

Hi I am having a problem with something that was relatively simple in Crystal and i am guessing it is purely my inexperience that is the issue here!
 
Calculated Field
 

=iif(Fields!Fun_Debt_Status.Value <> "debt","",

iif(max(Fields!Fun_Days_Overdue.Value)>30,"On Stop",

iif(max(Fields!Fun_Days_Overdue.Value)>0,"Overdue",

iif(sum(Fields!Fun_OS_Amount.Value)> Fields!CREDIT_LIMIT.Value,"Over Credit Limit","ok"))))
 
Want i am trying to do as you can probably see is create a "Account Status" field depending upon overdue days for payment etc..
 
My report just produces an error (internal) when i try and run - the calculated field above isn't even on the report.
 
Please let me know what i am doing wrong! I maybe going at it in completely the wrong way altogether,
 
Thanks in Advance!

View Replies !
Sort A Calculated Field
 

I have a quick question that i have just a simple calc field.
 
Field.Value-Field.value then i want to sort by the calculated results. The expression is fine i know it is written wrong here but i cannot figure how to sort by the result of the expression. Thanks.

View Replies !
My Problem With Calculated Field
I have a table for tracking the movement of cash register it has the fields

ID
Date
Amount_Debit
Amount_Credit
Explanation

I want to add a calculated field named balance that shows the actual balance of the cachregister after the entry in the row I

used this but it gave me an error

sum(amount_debit-amount_credit) where id<=id

the general idea is to get the summary of the rows that has an Id equal or less than the row id of the row that I want to show

the balance of it

can any one help me to get the desired result in the best way possible

additional question if possible can I get correct cash balance if I drop the ID field depending on date


I use SQL Server 2005 Express

View Replies !
Using Calculated Field In Where Clause
Dear All;

i want to use a calculated field in where clause but this does'nt works: e.g.;

select (colA + colB) as calcField
from tbl
where calcField > 100

what is the right way to do it, as i m getting error;
it works like :
select (colA + colB) as calcField
from tbl
where (colA + colB) > 100

but i m using a complex query as i m getting value from a function and then i hav to use that in where clause as well ;


Thanx in advance,


--
Muhammad Zeeshan

View Replies !
Re-using A Calculated Sub-select Field In A View?
I've been running into more and more complexity with an application, becauseas time goes on - we need more and more high-level, rolled-up information.And so I've created views, and views that use other views.. and the queriesare getting slower and slower.This morning, I'm working on something like this:select<some columns>,"calculatedcolumn" = (select top 1 crap from stuff wherethingy='whatchamacallit')fromsomeviewnow, I realized that I need to really return "calculatedcolumn" in a coupleother places in the select like this - well, this is what I WANT to do:select<some columns>,calculatedcolumn = (select top 1 crap from stuff wherethingy='whatchamacallit'),otherfield = case SomeBitwhen 1 then calculatedcolumnelse count(somefield)end,otherfield1 = case SomeotherBitwhen 1 then calculatedcolumnelse sum(somefield)end,otherfield2 = case SomeBit2when 1 then calculatedcolumnelse avg(somefield)end,otherfield3 = case SomeBit3when 1 then calculatedcolumnelse count(somefield)end,fromsomeviewPoint is, I CAN'T do that, so I have to re-run that sub-select for EACH ofthese cases, and that is KILLING this stored procedure. It seems to me, thatif the database when and already got that field, for that row - I should beable to re-use, rather than going back out additional times.Is there a way to so this? Put simpler:selectx = (select top 1 user_id from users),bestUser=x,smartestUser=xfromUserscan I re-use "x" in that example. Thanks!

View Replies !
Design Question: Calculated Field
I'm trying to create an OLAP system using SQL Server 2000 AnalysisServices (AS). I want the AS cube to be based on a database with astar schema.I have a field called Ratio. The initial ratio value is based uponthis formula: (CurrentTimePeriodAmount -PreviousTimePeriodAmount)/PreviousTimePeriodAmount. However, thatinitial ratio can be manually overridden and replaced. Then the ratiois used to calculate future Amounts.Should I place that calculated Ratio field in the "source" databasedesign or should it be part of the Analysis Services cube?

View Replies !
Create A Calculated Field That Gives Me The Avg 75 Percentile
I'm trying to create a calculated field that gives me the avg 75 percentile.

Right now I get this value by doing the following:

Create data set:

Select top 75 percent <field>

from <table>

Then I create the following calculated field

Avg(Fields!<field>.value,"<data_set_name>")

But I wanted to be able to create a calculated field that gives me the avg 75 percentile without creating a separate data set to get the top 75 percent Value.

Is it possible?

Thanks!

 

 

 

 

View Replies !
Calculated Field Crashes Vs 2005 Sp1 ?
Hi!

when I'm trying something litle bit more complex thing than string manipulation in calculated field ex: =RunningValue(Fields!SALES.Value, Sum)


It just crashes visual studio when trying to run the report?! I think this could state as a bug in RS?

View Replies !
Calculated Field Using Two Data Sets
Hi,
 
I'm trying to created a report.
Final report looks like this.







Total Loans/Lines (#)
13,283



Total Commitments ($ MM)
$1,703



Total Outstandings ($ MM)
$1,175






 
 A
 B
 C
 D
 F

Bankruptcy
0
$0
$0
0.00%
0.00%

Charge Off
0
$0
$0
0.00%
0.00%

 
Source table looks like this;
 






Bankruptcy        



 0

Charge Off



0

CLTV
131

DSR
102

Exc Total
265

FICO
7

Foreclosure/Repossession

Grand Total
13283

Loan Amount
32

 
Column D = A Bankrupcy(0) / Total Loans/Lines #(13283)
 
But it does not let me to use report expression as its not in the same scope.
 
Can anyone tell me how to do this calculation ?I was trying to use a report expression but it seems like not working.
 
Thanks

View Replies !
Sort A Report On A Calculated Field??
 

OK I have a report that needs an interactive sort on a calculated field. I get the message: "Report items cannot be used in sort expressions"
 
That's the whole reason we purchased SS*S and are putting up a Data Warehouse, so we can rank and analyze our data. Surely there is a way to do this??
Thanks for any advice!

View Replies !
Views - Filtering On Calculated Field
 

Our phone system keeps a list of events, such as login and logout, which I'm doing a self join on to get the start and end times so I can calculate the time between the start and end of each event during a time period.
 
Then I stuffed the self joins into a couple views for the events I'm interested in...
 
The problem is that this makes the "end time" a calculated field, so when I use it as part of the filter it takes forever.  I need to account for events ending within the time period, and events starting within the time period... so I need to filter on both the start and end time in the initial select.  Filtering the start time first in a subselect, then the end time in the main select is quick but can lose things that started before the start time.
 
So how can I speed up the filtering on that calculated column?
 
Or am I going to have to get really creative with unions?

View Replies !
Calculated Field In Footer...running Total
 

Hello, 

 

How do I add unique values on the report?  For example say I have this in my report:

 

Customer:                                   Food Purchased:                          Amount: 

Judy                                             Cat Food                                         $12

Sarah                                           Dog Food                                       $13.50

Diane                                           Rabbit Food                                   $17

Jason                                           Dog Food                                       $16

Tammy                                         Dog Food                                       $15

 

In the footer of the report I want to print a summary box that looks like this:

 

Product:                                      Number Purchased:                    Total:

Cat Food                                     1                                                     $12

Dog Food                                    3                                                     $44.50

Rabbit Food                                1                                                     $17 

 

 

How do I do this? 

 

Thanks!

View Replies !
Report - Interactive Sort On Calculated Field
Hello,

I have a report that calculates a field and therefore it does not exist in the dataset.

Can I perform an interactive sort on the textbox that contains this calculation?

Many thanks.

View Replies !
Adding A Calculated Field By Using Two Fields From Different Data Sets
 

Can I make a calculated field by using two fields from different data sets?(I'm talking about SSRS data sets)
 
I tried to do that. But I got a error message.

 
 

"Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope."

 
Please can some one help me out?

View Replies !
Creating A Calculated Field From Within VWD? (Visual Web Developer Express)
I'm trying to create a calculated field using SQL Server Express, from within the Visual Web Developer Express 2008 IED.  The field I am trying to create is called "total" and is supposed to be the sum of the subtotal, salestax, and shipping fields.

Is this possible from within VWD 2008?  How?


Thank you!!!

View Replies !
How To Make Row Calculated Query.
Please help me to get the result I want.

I have this table.
Date          Value
===          ====
1-Jan           100
1-Jan              80
1-Jan              20
2-Jan             50
2-Jan              30
2-Jan               5
2-Jan               15
3-Jan            120
3-Jan              80
4-Jan            45
4-Jan            55
5-Jan            120

How do I write the query to get the following result from above table.

Date  Opening    Value       Closing
1-Jan     0           200           200
2-Jan    200        100           300
3-Jan    300         200           500
4-Jan    500         100           600
5-Jan    600         120            720

Where, Opening column is 0 when there is no previous closing and Value column would be the daily total. The closing would be the Opening value + Daily Total and this value would Opening value for next line. Please help me how to write the SQL statement to get this result from above table.

Thanks in Advanced,
AV

View Replies !
Report Model: Drill On Calculated Field In Report Builder
Hi,

I've created dsv that contain all fields from table database. in the smdl I've remove some fileds due to security. All fields in the smdl do not contain drill.

Issue: When I created calculated field in the report builder the field has a link. When I clicked the drill I saw all the record data including field that not in the smdl.

Questions:

1) Can I remove the link from the calculated fields?

2) Can I prevent from users drill to fields that not in the smdl?

Thanks,

Assaf

View Replies !
Simple MDX Query: Multiple Non-Contiguous Members From Same Dimension In Calculated Member
Hi
 
A very basic MDX question. Using the following from AdventureWorks as an example:




Code Snippet
WITH MEMBER [Measures].[Big Cities]
AS
(
[Geography].[City].&[New York]&[NY]
, [Measures].[Internet Order Count]
)
SELECT
[Measures].[Big Cities] ON COLUMNS
, [Customer].[Total Children].Children ON ROWS
FROM [Adventure Works]
 
 
How would I re-write the [Measures].[Big Cities] calculated member so it included both [Geography].[City].&[New York]&[NY] and [Geography].[City].&[Los Angeles]&[CA]? Assuming there is no logical connection between these members, and that they are non-contiguous. Also, in my real example, I cannot move [Measures].[Internet Order Count] to the WHERE clause, it must remain within the calculated member.
 
Thanks,
 
Julia.
 

View Replies !
Max Of Date Field In Query
I have a table with date fielde.g.  SrNo         Date 1            1-MAR-2008 2            3-Mar-2008 3            7-Mar-2008 4            10-Mar-2008 5            15-Mar-2008 I need a query to find out Max date which is less than '8-Mar-2008' .  i.e i need single output '7-Mar-2008'anybody helpThanks 

View Replies !
How To Split The Field In The Sql Query?
      I have the field LocationID (string)which has values  like
          "AZ001","AZ002","IN002","IN004"  first 2 will be always alphabets and remaining 3 will be numbers,
I want to split it  like "AZ" ," 001"
                              "AZ","002"
                              "IN" "002"
                              "IN" "004"
now i will populate dropdownlist with  unique values of "AZ" "IN"
according to  first dropdownlist how i will populate second dropdownlist?
So how to write sql query for splitting? and then populating the dropdownlist ?
 
 
 
 

View Replies !
SQL DateTime Field Query
I was wondering if someone could help me here with some reporting I'm trying to do. For website visits, I currently use getdate() to have SQL insert the date and time of the visit in the table. I was wondering, is there a way to grab just the month from the field? I would like to chart this and I need to group the visits by month. I'm not sure how I would go about filtering just the month out of the entire date and time fields.

View Replies !
Empty Field Query
Hi Friends,

I have one query that i have to Replace the Empty Value of a filed with some other value how can i do in SQL??

ID Phone Name
1 122 abc
2 xyz
3 444 mmm
4 525 ccc
5 nvb

Now i want replace the blank (Empty) filed with some charaters Numbers how can i do that?? any Help

Ashu

View Replies !
Identity Field With A Query ?
I want to kown if a field is an identity (counter) using a query or a stored procedure ?


Thanks

View Replies !
How Do I Query For Particular Criteria In Every Field In The Db?
I need to query a table for a record only if there is a certain text string in ANY OF THE TABLE'S fields. I know of using the WHERE clause with logical OR (e.g. - WHERE field1 = 'xyz' or field2 = 'xyz' or ...) but there is a limit of 40 expressions with an Access database, and I have 102 fields to look through! That's my dillema. I know I may need to go to MSSQL or Oracle, but I'd rather stay with Access. Is there a syntactical way to express the query I need? Or do I have to look somewhere other than Access for my database needs? Thanks for the advice!

View Replies !
SQL Query: Missing Field Value
Suppose in a table, there is some data in a field: 1, 2, 3, 5, 6, 8, 9. I need a sql query which will list the missing numbers: 4,7 (Missing digits)

Query: Select * From table1

field
------
1
2
3
5
6
8
9

Expected query:??

filed1
------
4
7

Please help me to get a query which will provide my expected data.

Thanks.

/Fakhrul(mfhossain@gmail.com)

View Replies !
Query Detail As A Field.
I have two tables(Order and OrderDetail) of master-detail relationship.  I have a nchar field in the detail table called itemno.  I want to query like:
 
Select Order.OrderNo, Order.Date, SUM(OrderDetail.ItemNo) as ItemNos,....
From Order Inner Join OrderDetail on Order.OrderID=OrderDetail.OrderID
Where Order.OrderID=10
 
so that the resulting field ItemNos will become a string in format "ItemNo01, ItemNo02, ItemNo03,...."
How can I write this query in T-SQL?
Thanks

View Replies !
Really Simple Query Needs Another Field
I have written this query in SQL

select * from wce_contact
where (Mail3Date <= '2007-09-25')
AND NOT (Mail1Date is NULL )
AND NOT (Mail2Date is NULL )
AND (Mail4Date is NULL )
AND (Mail5Date is NULL )
AND (Mail6Date is NULL )
AND (Mail7Date is NULL )
AND (Mail8Date is NULL )
AND (Mail9Date is NULL )
AND (Mail10Date is NULL )
AND (Mail11Date is NULL )
AND (Mail12Date is NULL )
AND (Mail13Date is NULL )
AND (Mail14Date is NULL )
AND (Mail15Date is NULL )
AND (Mail16Date is NULL)

Little bit of background info - We have a database of over 500k websites with email addresses. We use email marketing to contact these sites and everytime they get mailed i need to fill in the MailDate field. Obv Mail5Date means they have been emailed 5 times etc The above qry is trying to find all contacts that have been mailed 3 times and havent been mailed in the last 42 days.

I also have an IDStatus field that allows me not to use the contacts that have opted out our mailing or website shutdown etc I try adding this to the bottom of the query

AND (IDstatus is Null)

But the query runs and finds 0 contacts which i know isnt the case, as when i use our front end database application it produces results.

I was wondering if anybody could possibly help me?

Thanks!

View Replies !
Sort On Field Constructed In Query
I want to sort on a field that I construct during a query....how can I solve this?Basically what i am doing is selecting mediafiles with comments in descending order. (so mediafile with most comments on top)Here's my (not working) query, because it throws the error that the mediaComments column is unknown....SELECT *FROM(select ROW_NUMBER() OVER (ORDER BY mediaComments DESC) as RowNum,m.title,m.usercode,mediaComments=(select count(*) from MediaComments where mediaid=m.mediaid)FROM Media m WHERE m.usercode>0group by  m.title,m.usercode) as InfoWHERE RowNum between @startRowIndex AND (@startRowIndex + @maximumRows-1)

View Replies !
Query To Sum The Same Field Twice In The Select Statement
 Hello friends ,    I have table (MoneyTrans) with following structure
[Id] [bigint] NOT NULL,
[TransDate] [smalldatetime] NOT NULL,
[TransName] [varchar](30) NOT NULL, -- CAN have values  'Deposit' / 'WithDraw'
[Amount] [money] NOT NULL
I need to write a query to generate following output
Trans Date, total deposits, total withdrawls, closing balance
i.e. Trans Date,  sum(amount) for TransName='Deposit' and Date=TransDate , sum(amount) for TransName=Withdraw and Date=TransDate , Closing balance (Sum of deposit - sum of withdraw for date < = TransDate )
I am working on this for past two days with out getting a right solution. Any help is appreciated
Sara

View Replies !
DISTINCT SELECT Query With More Than One Field
Hello, I want to do a DISTINCT  SELECT query with more than one field, for example a ID field with a Type field, as if both fields make the primary key, like (ID 1 ,Type 1) ,( ID 1, Type 2) and (ID 2, Type 1) is ok but not (ID 1, Type1) and (ID 1,Type 1) if its not possible to do a distinct with more than one then what other techniques are possible to get the duplicate data out.   the reason why I want to use distinct is that I can use that query to export that data to where both of these fields make the primary key.
Thanks in advance

View Replies !
SQL Query - Search Field For String
Hi,
I have a SQL server 2005 database with a series of multiple fields. One of the fields has a array of strings seperated by semi-colons like so: Red;Green;Blue
My question is, how can i run a query on all of the fields that have the value of say Green in it. Note that these values vary in different order and numbers.
Thanks

View Replies !
Help! - Query On Time Field In SQL Server - How?
Hi,I have an orders database and I need to be able to write a querythat groups sales by:1. Date2. Time of day (both am and pm)I currently have a date/time field named "Submitted" that storesjust the date.However, how do I store the time?I know I can store the date/time in the "Submitted" field Icreated. However, because of the time being stored in that field, Ican't execute an easy query such as:select * from database where submitted = '2/10/05'(reason being, the time portion makes each "Submitted" fieldrecord unique, so just the date won't be recognized)I realize there probably is a much better way to do this in theSQL query language that I am not aware of.Two questions:1. Based on what I'm trying to do -- query based on date and groupby number of sales for each hour of the day (am and pm) -- what is thebest approach to store the time?2. What does the query look like that querys by date and groupsorders by time of day (am and pm)?Thanks for your help.J

View Replies !
How To Query By Keyword For Image Field.
If the data type of field is "varchar",we can use "like" to query if it hassome substring.Such as "where custom.valuevariant like '%Verizon%' ", it will query out allrecords that contains string "Verizon".But how to do when data type of field custom.valuevariant is "image"?Thanks

View Replies !
Query Out An Xml Element From A Field Containing Xml Data
'message' Field Data:<xml>....<test>ABC</test>....</xml>How do I query out 'ABC' from this xml field data in a SQL Server?Assume message field is in table 'Persons'

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved