Reuse Calculated Values

Nov 14, 2006

What is the best code pratice to use do the following code,

SELECT
fo.no as LNum,
fo.name as LName,
sum(CASE fo.docnome WHEN "In" THEN fo.etotal ELSE 0 END) as In1,
sum(CASE fo.docnome WHEN "In2" THEN fo.etotal ELSE 0 END) as In2,
sum(In1+In2)/10 as inDec,
from fo group by fo.no,fo.name order by fo.name

instead of

SELECT
fo.no as LNum,
fo.name as LName,
sum(CASE fo.docnome WHEN "In" THEN fo.etotal ELSE 0 END) as In1,
sum(CASE fo.docnome WHEN "In2" THEN fo.etotal ELSE 0 END) as In2,
((sum(CASE fo.docnome WHEN "In" THEN fo.etotal ELSE 0 END))+sum(CASE fo.docnome WHEN "In2" THEN fo.etotal ELSE 0 END)))/10 as inDec,
from fo group by fo.no,fo.name order by fo.name

I cant use functions and procedures. Is there any better and cleaner way to code this, reusing the calculated values?

View 1 Replies


ADVERTISEMENT

How-to Return Calculated Values From A Called SP

Dec 11, 2001

Can someone please reply w/ example syntax on how to receive calculated variables from an invoked SP. DESCRIPTION:

sp_caller invokes sp_calc_values (passing @var1, @var2) via:
exec sp_calc_values @var1, @var2

sp_calc_values receives @var1, @var2 then calculates @var3, @var4

HOW does sp_caller receive the calculated values @var3, @var4 ???

thx in advance

View 2 Replies View Related

Calculated Values And Database Design.

Jul 20, 2005

Hi everybody,I need some help on calculated values in my database design.I'm creating an accounting / business management application with theusual modules like A/R, A/P, Inventory, etc.I don't know how to handle calculated values in fields like "CustomerBalance", "Inventory Item Qty on Hand", "Inventory Item Qty Last cost"and other similar.I don't want to create fields in the database to store these valuesbut I want to create them on the fly instead. Another thing I preferto do is use code in my application (vb.net) not T-SQL to do this(stored procedure or views), because this way I'm moving businesslogic into SQL; so far all the logic is located in a Business RulesDLL.My question is how can I do that and at the same time achieve "easy"joins.For example:Every time I retrieve some customer's info I need his balance. Let'ssay if my query is:SELECT CustomerID, CustomerName, Address from CustomersWhere CustomerID = ‘xxxxxx'How can I retrieve the balance, when is calculated from other fieldsin other tables, such as Invoices, Credit Memos and Cash Receipts?I thought to use views and add a join to the above query. Is that goodor bad, performance wise?What other options I have?Looking forward for your answer.Thanks in advanced.Stefanos

View 3 Replies View Related

Null Values In Calculated Fields

May 22, 2008



Hi all

I have a calculated fields in report designer such as a + b + c + d. In sql server if I run this query

select a + b + c + d from table1

and any of a,b,c or d is null, the result is null.

whereas in calculated fields, it does not return null but infact ignores the null value and treats it as zero.

I want my calculated field to be null if any of the values are null.
Is it possible? I cannot use the isNothing function because I have too many fields and it will be quite cumbersome.

Thanks

View 4 Replies View Related

How Are The Key Influencers Impact Values Calculated?

Jan 24, 2008



Hi,


Does anyone know how the key influencers impact values are calculated? Thanks!!

Kate

View 3 Replies View Related

Calculated Values In Target Table

Dec 12, 2007

Hi,

is there any way to fill up tables with calculated valued? My Source Table is build-on like this example:

CustNo / Year / Variable / Value
100 / 2005 / var1 / 321.90
100 / 2005 / var2 / 44.20
100 / 2006 / var1 / 12.09
100 / 2006 / var2 / 7.91
101 / 2005 / var1 / 23.78
101 / 2005 / var2 / 67.22

My Target Table should have this result:

KPI / CustNo / Year / Value
KPI1 / 100 / 2005 / 366.10
KPI1 / 100 / 2006 / 20.00
...

What I want to accomplish? I want to add var1 and var2 from Customer 100 in Year 2005, but is this possible with standard tasks in SSIS?

bye
Jonas

View 6 Replies View Related

Power Pivot :: DAX Calculated Measure For Sum Of Max Values

Sep 21, 2015

We have a client that wants to take the Max value of a count at the Product level, but then for each Brand (Parent of product), sum the Max values for that particular slice.  The example below shows the Max sales per month over the last 6 months. 

Prod1 had it's best month in Month2 (20 units) and Prod2 had its best month in Month4 (30 units).  Brandx should roll up to 50 units.  Can DAX handle this in a single Calc Measure?

Brandx          50
    Prod1        20
    Prod2        30
Brandy          60
    Prod5        40
    Prod6        20

View 2 Replies View Related

Retrieving Scalar Or Calculated Values From Stored Procedures With C#

Feb 4, 2007

I am trying to build an Sql page hit provider.  I am having trouble getting a count back from the database.  If I use ExecuteScalar it doesn't see any value in the returned R1C1.  If I use ExecuteNonQuery with a @ReturnValue, the return value parameter value is always zero.  Ideally I would like to use a dynamic stored proceudre if there are any suggestions for using them with C#.  My table has rvPathName, userName and a date.  I have the AddWebPageHit method working so I know data connection and sql support code in provider is working.  I think the problem is either in how I am writing the stored procedures or how I am trying to retrieve the data in C#.  Any help with this will be greatly appreciated.

View 5 Replies View Related

Analysis :: Create A Calculated Set From Union Of Values In Two Sets?

Oct 26, 2015

I have the following MDX Query:

Select {measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
[Cost Centres].[Cost Centre].[All].Children
[Locations].[Locations].[All].Children
on 1
From MyCube

which produced the following table:

Division
 Cost Centre
 Location
 Dollars
AA
1
X
$30.00

[code]....

What I am hoping to do is create a set out of the Union of specific values in the [Cost Centres].[Cost Centre] and [Locations].[Locations] hierarchies into a single set and use that new set in my MDX query across the columns.

Using the table and query from above, I have the following conditions that would determine the value in the set (lets call the new set 'NewSet')

When Cost Centre = 1 and Location = X Then "CustomType1"
When Cost Centre = 1 and Location = Y Then "CustomType2"
When Cost Centre = 1 and Location = Z Then "CustomType3"
When Cost Centre = 2 and Location = Y Then "CustomType4"
When Cost Centre = 2 and Location = Z Then "CustomType5"Else "Default"

Then, if I was to execute the new query:

with

set NewSet as "Some Unknown Magic Here"

Select {measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
{NewSet}
on 1
From MyCube

I would end up with 

Division
 NewSet
Dollars
AA
CustomType1  
$166.64
AA
CustomType3 
$64.24
BB

[code]....

View 2 Replies View Related

HELP To Write Stored Procedure Whose Values Are Calculated Automatically In Database

May 12, 2007

 Hi frdz,    I m creating my web-application in asp.net with C# 2005 and using sql server 2005.    I have created the stored procedure for the insert,update.    I want to know how to write the mathematical calculations in the stored procedure..    Pls tell me from the below  stored procedure  were i m making the mistake  ??    As the discount and the total amount are not calculated by itself....and stored in the database   How to convert the @discpercent numeric(5,2) to@discpercent ="NoDiscount" should be displayed when no discount is being given to the customers....     ALTER PROCEDURE CalculationStoredProcedure

@accountid int output,
@accountname varchar(20),
@opbal numeric(10, 2),
@opbalcode char(2),
@total numeric(10, 2),
@clbal numeric(10, 2),
@clbalcode char(2),
@discpercent numeric(5,2),
@discamt numeric(10, 2)


as


begin
set nocount on



if @opbal IS NULL OR @opbal = 0

begin
select @opbal=0
select @opbalcode= ' '
select @clbal= 0
select @total= 0
select @clbalcode= ' '
@discpercent ="NoDiscount"
@discamt=0
end




select @accountid = isnull(max(accountid),0) + 1 from accountmaster



select @total=@opbal - @clbal from accountmaster
select @discamt=@total* @discpercent/100 from accountmaster

begin
insert into accountmaster
(
accountname,opbal,opbalcode,clbal,clbalcode

)
values
(
@accountname,@opbal,@opbalcode,@clbal,@clbalcode
)

end

set nocount off
end

      Thanxs in adv... 

View 7 Replies View Related

SQL 2012 :: Calculated Columns Conditional On Calculated Columns Multiple Tables

Apr 20, 2014

I have 4 tables involved here. The priority table is TABLE1:

NAMEID TRANDATE TRANAMT RMPROPID TOTBAL
000001235 04/14/2014 335 A0A00 605
000001234 04/14/2014 243 A0A01 243
000001236 04/14/2014 425 A0A02 500

TRANAMT being the amount paid & TOTBAL being the balance due per the NAMEID & RMPROPID specified.The other table includes a breakdown of the total balance, in a manner of speaking, by charge code (thru a SUM(OPENAMT) query of DISTINCT CHGCODE

TABLE2
NAMEID TRANDATE TRANAMT RMPROPID CHGCODE OPENAMT
000001234 04/01/2014 400 A0A01 ARC 0
000001234 04/05/2014 -142 A0A01 ARC 228
000001234 04/10/2014 15 A0A01 ALT 15

[code]...

Also with a remaining balance (per CHGCODE) column. Any alternative solution that would effectively split the TABLE1.TRANAMT up into the respective TABLE2.CHGCODE balances? Either way, I can't figure out how to word the queries.

View 0 Replies View Related

Log Reuse Help

Apr 30, 2007

Dear Folks,
I'm getting the error with application like this..............

"the transaction log for database "mydatabase" is full.....to find out why space in the log can not be reused, see the log_reuse_wait_desc column in sys databases. "

I've checked with the column, there are totally 3 options.(I've checked with all other databases)
1)checkpoint,
2)log_backup,
3)nothing

what can i choose for this error to be suppressed?
actually there was log_backup option.

please guide me in this regard.........

thanks in advace.

Vinod

View 1 Replies View Related

How Do I Reuse A SqlDataAdapter

Apr 25, 2007

It's a pretty basic question but I haven't been able to find any examples out there.  I dimmed a dataadapter and would like to reuse later in my code (line 3 in the code below).  What is the correct syntax to do this? Dim da As New SqlDataAdapter("SELECT * FROM myTable", conn)da.Fill(myDataTable)da.______  ("SELECT * FROM myTable2", conn)da.Fill(myDataTable2) 

View 2 Replies View Related

Can We Reuse SqlParameter's?

Jul 10, 2004

Hi,

I am getting the following error:

The SqlParameter with ParameterName '@pk' is already contained by another SqlParameterCollection

If I could work out what code to post I would, but I can say that I am managing my Sql data in my code by caching small arrays of SqlParameter objects as pulled from the database. If I need to update the DB I change the cached SqlParameter and re-insert it. If I perform a SELECT I check the cache first to see if I already have the SqlParameter.
However, currently, I am experiencing the above error when performing a select, then later an update, followed by another update.
Would I be correct in saying that a SqlParameter object can only be used once for a database operation and should be discarded? Would I be correct if I said that the SqlCommand object should be discarded? I am barking up the wrong tree entirely?

Distressed in DBLand,
Matt.

View 2 Replies View Related

How Can I / Should I Reuse SqlCacheDependency? Thanks

May 1, 2006

I can create a SqlCacheDependency, and link it to a cached item in httpcontext cache. When something change, it will remove the cached item from the cache. I think I have to redo the process when that happens - prepare sql command, create SqlCacheDependency and insert the item into cache. Now I only need a notification from my SQL when something changes in one of my table, I don;t need read anything from db, and I think I should find a way to not recreate the SqlCacheDependency object everytime?
any suggestion?

View 2 Replies View Related

Reuse Deleted Primary Key Id

Dec 15, 2007

Hello,          Can I reuse the deleted primary key id? I'm using SQLServer2005. cheers,imperialx   

View 6 Replies View Related

Stored Procedure Reuse

Jul 23, 2005

I wonder if there is a solution for this in SQL 2000 (or do I have towait for SQL 2005)?I am currently in the middle of developing a 'Yahoo' style portal whichwill be rolled out in about 20 or so countries. I have set up in SQLServer one database per country. All the portals have the samefunctionality - but show different data.Is it possible to have a single database which holds storedproceedures, functions and views and have the individual countrydatabases use these?Note: I want to avoid using EXEC sp_executesql.I look forward to some good news on this! Thank you in advance.Dadou.

View 2 Replies View Related

Cannot Reuse Database Name After Deleting Old One

Apr 19, 2008



Hi. I'm starting to try out LINQ to SQL, and so I'm using SQL Express (on Vista) to experiment. My problem is that once I create and delete a database, I can never use the name again. If, after deleting the old database, I try to create another one with the same name (say Acct1), I get "Create failed for Database 'Acct1'. An exception occurred while executing a Transact-SQL statement or batch. The logical file name "Acct1" is already in use. Choose a different name. Error: 1828"

I am trying to create the database in SQL Server Management Studio Express. That database name does not appear in the list of databases: there is only AdventureWorks and the system databases. The .MDF and .LDF files have been deleted. Not just sent to the recycle bin, but permanently deleted.


I have already used up Acct1, Acct2, and Acct3, just to try out different scenarios. Each time, I delete the old database before trying to create a new one with the same name, but I am forced to always supply a new, different name. I have checked the directory with hidden files and system files showing to be sure there is no old file lurking there somewhere.


Is there a way to delete these old "logical file names"? I can't even find any reference to their existence except for the message that says they are already in use.

View 11 Replies View Related

Transact SQL :: How To Reuse Subquery

Jul 29, 2015

with c1 As (
select 1 As '1' , 2  As '2' , 3 As '3'
) 
, c2 As (
select 4  As '4', 5  As '5',  6 As '6'
union all
select 1 , 2 ,3 from c1  -- >>>>>  select from c1 here 
) select * from c2 
  union all
  select * from c1 -- >>>>>> and select from c1 here 

According to the query above , I try to reuse the subquery by put  the subquery into 'with cte'  name (c1)  then i select this  2 times .

if I do this way , how many time this subquery (c1) execute ?
if 1 time then this is the right way to reuse this subquery .
if 2 times  , it is not then what should i do to reuse this subquery ?

View 3 Replies View Related

Reuse Of Conversation Handles

Nov 26, 2007



I have read the articles posted online concerning different dialog reuse strategies. Most of them create a new table in the sender to hold dialog ids. I was wondering what is wrong, if anything, with the following approach:




Code Block
declare @dlg uniqueidentifier
select top 1 @dlg = conversation_handle from sys.conversation_endpoints where state IN ('CO')
if @dlg is null
begin
begin dialog conversation @dlg
from service [tcp://SFT3DEVSQL01:4022/TyMetrix360Audit/DataSender]
to service '//TyMetrix360Audit/DataWriter','386DDD04-7E55-466A-BE83-37EFC20910B9'
on contract [//TyMetrix360Audit/Contract] with encryption = off;
end
;send on conversation @dlg
message type [//TyMetrix360Audit/Message] (@msg)





Here I simply select a conversation handle directly from the sys.conversation_endpoints table. Can anyone see any issues with this approach?

Thanks in advance....

View 6 Replies View Related

Reuse Of Field Aliases

Jan 3, 2007

I have been working with SQL for quiet a while but think this perhaps is a very basic question that has always escaped me:

At my work I was exposed to both, MS SQL Server 2000 and Sybase Adaptive Server Anywhere/Sybase SQL Anywhere.

Under Sybase I was able to use aliases in other calculations and filters but i have never been able to do the same with SQL.

Example:
In Sybase I can write this:

Select Price * Units as Cost Cost * SalesTax as TotalTaxFrom Invoice Where TotalTax > 3.5
However if i want to do this in MS SQL 2000 i have to go trough


Select
Price * Units as Cost
Price * Units * SalesTax as TotalTax
From Invoice
Where (Price * Units * SalesTax) > 3.5

In the long run this is costing me a lot of code redundancy, not to mention a debugging nightmare. Is there a way to replicate this alias usage in MS SQL Server?

View 3 Replies View Related

Reuse Of Report Elements

Jun 5, 2007

I am working on a project developing a fairly large number of reports with a team of developers. Many of these reports have common elements and code, such as common headers with user-selectable colors. Additionally, many of the common parts of the reports are at mockup stage currently, and many features will have to be added to the reports as time goes on.



We're attempting to create a generalized framework that will minimize the duplication of effort as we develop these reports, and as we go back and modify or fix them later.

What is the best way to approach this?



My first attempt was to create a report template and base all the reports off of the same template. That was fine for the first pass, but as we need to make changes later, they will not be propagated to the already existing reports.



My second attempt was to have each componant of that template reference a subreport, so that changes to the actual report template will be minimized as we go forward. This works great for minimizeing work, but it appears that you lose many features with the use of subreports, and there seems to be a pretty serious performance impact as well. I have posted about one such issue here: Pagination



If anyone has pointers about how to go about this, and where I should start, they would be greatly apreciated!

View 2 Replies View Related

Reuse Deleted Identity In Table Again

Jun 19, 2014

I have a table in which there is a column of type identity(1,1),in the same table i have bulk data, and i have deleted a row from my table, so now i want to reuse that same Id again, how to do that.

View 3 Replies View Related

Reuse Numbers In Identity Column

Mar 4, 2008

Hello,

I have an ID column which is an Identity column, and it counts from 1 upwards.

If I have 10 records, I have ID's number 1 to 10.
If I then add another record, it will give the ID number 11.

Imagine I then delete ID number 9
Is it possible to get the next record I create to take number 9 instead of 12 ?

View 5 Replies View Related

How To Reuse Functions In Script Tasks ?

Feb 7, 2006

Hello

I have some common functions that i use in several script tasks. How du i store a function globaly so that i can use it from different projects and still only have to edit it one place ?

View 4 Replies View Related

ReUse Common Surrogate Key Pipeline

Jun 12, 2007

I have several stage to star (i.e. moving data from a staging table through the key lookups into a fact table) ETL transformations in a single SSIS package. Each fact table has a different set of measures but the identical foreign key set, e.g. ConsultantKey, SubsidiaryKey, ContestKey, ContestParamKey and MonthKey.



Currently I have to replicate the key lookup (Surrogate Key Pipeline, or SKP) for each data flow. If I could cache each dimension one time in the package and reuse it for each stage to fact it would be much more efficient.



Is there a way for me to reuse a common data flow?

View 6 Replies View Related

Reuse Existing Connection String For TableAdapter?

Jan 25, 2008

I've added a typed DataSet and dragged a table across from the server explorer. When I click configure on the table adapter, then click previous back to the "Choose Your Data Connection" dialog. The only option is the new connection that was just created when I added the sql server to the server explorer. Is there anyway to reuse my existing web.config connection string? My goal is to have a single connection string in my web.config.
 Thanks.
 -David

View 3 Replies View Related

Connection Manager Reuse For Oracle And SQL Databases

May 2, 2008

I'm trying to implement a configurable way of executing a group of SQL statements using either an Oracle or SQL database as the source for the data.

I'm currently building a connection string with a Script Task and then assigning it to a package variable so that it can be used by a connection manager but this only works with a SQL OLEDB connection.


I'm holding all the connection details in a database table, hence the need for the scripting but would it be possible to extend the task to reuse a single connection manager by changing it's properties?

View 7 Replies View Related

The Client Was Unable To Reuse A Session With SPID XX

May 11, 2007

Hello,



We have a recurring problem with one of our MS SQL Servers (MS SQL Server 2005 SP 1).

The SQL Server serves as a database server for a Web application with approximately 1500 users, the server is dedicated for the DataBase server.



The scenario is that the database servers cpu peaks at 100% and stays there until restart of the SQL Server service.



The error message from the applicatoion log:



Event Type: Error
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 18056



The client was unable to reuse a session with SPID 94, which had been reset for conection pooling. This error may have been caused by an earlier operation failing. Check the error logs for failed operations immediately before this error message.



SPID varies.



Anybody that knows anything why this error occurs?



Regards

John

View 25 Replies View Related

ADO Connection Pooling Error: The Client Was Unable To Reuse A Session With ...

Apr 13, 2006

Hello,

We are running SQL2K5 and have a Web server with a family of sites all sharing an identical connection string to enable ADO connection pooling between them. Today for about 20 minutes we had several (all?) connections from one site that uses a specific DB get a connection reuse error which showed in out SQL logs:

DESCRIPTION: The client was unable to reuse a session with SPID #, which had been reset for conection pooling. This error may have been caused by an earlier operation failing. Check the error logs for failed operations immediately before this error message.

We also have SQL Server slowdown and log in problems from other applications that seemed a symptom of this, or some third unknown cause. Note, the # means the run-time spid number was inserted. The misspelling "conection" comes right out of sys.messages (it is not our custom error):

select top 10 * from sys.messages where message_id = 18056

The immediately preceeding error in the SQL Log was always:
Message
Error: 18056, Severity: 20, State: 29.

Where Severity and State vary, but "Error: 18056" is consistent, although I can find no documentation on "Error: 18056" through Google or MSDN.

Also, the "The client was unable to reuse a session ..." error seems not to be referred to anywhere.

In our IIS logs, the matching entries are of the form:

[DBNETLIB][ConnectionRead (recv()).]General network error. Check your network documentation.

and

Invalid connection string attribute


My questions: Does anyone have experience with this error? We have real good history with ADO connection pooling, but can a "bad" connection be pooled, and if so can it be "flushed" or the pool "drained"?

Thank you for anything you have to offer!



View 13 Replies View Related

Is There A Hack That Would Allow You To Reuse Identity Numbers That Were Orphaned By Deleted Records?

Aug 24, 2006

I guess this is a fairly common topic but couldn't find the right words to find anything in a search.

What I'm getting at, is there any tsql functions or combination of commands for the following.

You have identity columns in your tables, if you set the a seed and autoincrement, I enter in rows 1 -10 and then I delete 4, 6, 7, 8.

My next new record uses 11. Is there any logic that allows you to check and reuse 4, 6, 7 & 8 described above? Not looking for something that consists of having to create an extra ID table for each table and handle configuring what the next available number is everytime an Insert or delete is called.

Thanks.

View 4 Replies View Related

Reuse Existing Data Flow Components In A Custom Data Flow Component

Aug 29, 2007

Hello,

Is it possible to use existing data flow components (Merge Join, aggregation,...) in a custom data flow component?

Thanks,

Yoann

View 15 Replies View Related

Can't SUM A Calculated Value

Oct 10, 2007

I know you can't aggregate a calculated value and I'm having a problem finding a solution


I have 3 groups: Course(1), Term(2), Category(3). Course = a particular class (i.e) Algebra; Term = 1 iof 4 terms in our school year; Category = for a class, one may have multiple categories like, participation, homework, quizzes, test, etc.


A class can be weighted for a Category like homework and will count 20% of the grade, tests 40% of the grade and so on. For each Category, I calculate the weighted total using the following:


=iif(Fields!Weight.Value<>0,sum(Fields!Earned.Value)/sum(Fields!Poss.Value)*Fields!Weight.Value*.01,0)


My delema is to sum up all those calculated values in the Term footer.


Thanks

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved