473,769 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying To find a Match in computed columns

I need to create an function similar to the "MATCH" function in Excel
that evaluates a number within a set of numbers and returns whether
there is a match. I have put the example of what I see in excel in the
check column. The "0" answer in the result column is in the fourth
account in the list. Somehow I need to loop through the accounts
comparing the result to the total and indicate a match in the check
column. It wouldn't even need to tell me the row number; it could be a
0 or 1.

account total result check
12377026 6.84 124.21
12377026 131.05 0 4
12377026 164.38 -33.33
12377026 0 131.05
12377026 78.71 52.34
12377167 -31.34 221.89
12377167 31.34 159.21
12377167 38.55 152 5
12377167 31.34 159.21
12377167 152 38.55
12377167 490.91 -300.36
12377167 0 190.55
12377167 0 190.55
12377167 -31.34 43.34
12377167 31.34 -19.34
12377167 38.55 -26.55
12377167 31.34 -19.34
12377167 152 -140
12377167 490.91 -478.91
12377167 0 12
12377167 0 12
12377363 47.05 84
12377363 131.05 0
12377363 -45.38 176.43
12377363 -47.05 178.1
12377363 47.04 84.01
12377363 -47.04 178.09
12377363 47.05 84
12377363 541.11 -410.06
12377363 0 131.05
12377363 672.15 -541.1
12377507 37.64 152.91

May 26 '06 #1
3 1628
(sk*******@sfmc-gi.org) writes:
I need to create an function similar to the "MATCH" function in Excel
that evaluates a number within a set of numbers and returns whether
there is a match. I have put the example of what I see in excel in the
check column. The "0" answer in the result column is in the fourth
account in the list. Somehow I need to loop through the accounts
comparing the result to the total and indicate a match in the check
column. It wouldn't even need to tell me the row number; it could be a
0 or 1.


I'm afraid that the MATCH function is unknown to me. I tried to read
about it the Excel Help, but in a hurry I could not make much out of it.

I was trying understand the numbers. I looks bit like credit/debit,
but the names "total" and "result" indicates something else.

So I would suggest that you give a more detailed explaination of your
business problem.

An extra hint is that if you include a CREATE TABLE statment for your
table and INSERT statements with the sample data, you are likely to
get a tested solution.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 26 '06 #2
On 26 May 2006 12:07:40 -0700, sk*******@sfmc-gi.org wrote:
I need to create an function similar to the "MATCH" function in Excel
that evaluates a number within a set of numbers and returns whether
there is a match. I have put the example of what I see in excel in the
check column. The "0" answer in the result column is in the fourth
account in the list. (snip)

Hi skosmicki,

Fourth by what definition? I can see that it's fourth in the order yoou
wrote the rows, but I don't see any appparent logic in the ordering of
rows with the same account. Remember that SQL Server doesn't keep track
of the order in which rows are inserted - if that's relevant to you,
you'll have to add a column for it.
Somehow I need to loop through the accounts
comparing the result to the total and indicate a match in the check
column. It wouldn't even need to tell me the row number; it could be a
0 or 1.


Maybe something like this? (Untested - see www.aspfaq.com/5006 if you
prefer a tested reply)

SELECT a.account, a.total, a.result,
CASE WHEN b.account IS NOT NULL THEN 1 ELSE 0 END AS check
FROM YourTable AS a
LEFT OUTER JOIN YourTable AS b
ON a.account = b.account
AND a.result = b.total

--
Hugo Kornelis, SQL Server MVP
May 26 '06 #3
Thanks Hugo - that's exactly what I did. It's a much cleaner result
set then looping through all the transactions.
Thanks Erland for your advice on the CREATE TABLE - I'll do so next
time. Keep up the good work!
Sherry

May 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7238
by: Paulo Andre Ortega Ribeiro | last post by:
I have a table with fields called fname (First Name) and lname (Last Name). I need the user´s email thai is compose from lname and fname: LOWER(LEFT (fname,1) + lname) Is there any difference between creatig this computed column ia a table or in a view in SQL Server 2000? I can do: 1. CREATE TABLE Users(
2
11324
by: tperovic | last post by:
Using SS2K, I'm getting the following error while bulk inserting: Column 'warranty_expiration_date' cannot be modified because it is a computed column. Here is my bulk insert statement: BULK INSERT dbo.TestData FROM 'TestData.dat' WITH (CHECK_CONSTRAINTS,
9
3694
by: DMAC | last post by:
If i want to split a computed column into two or more columns based on the the length (its a varchar) of the computed column, how often will sql server determine what the computed column is? roughly along the lines of select comp_col,'comp_col 2'= case when datalength(comp_col)<=100 then comp_col else left(comp_col,99) + '~' end, datalength(comp_col) from aTable
1
1391
by: GJK | last post by:
In SQL Sever, do the size of computed columns gets added to the total size of the tables? Does SQL server stores the actual values in computed columns? Thanks _GJK
12
2551
by: Andy Jeffries | last post by:
Hi all, I want to write a function that given two elements will make their heights equal to the larger element. I've had a go at it and it works, but it makes both their heights larger than either of them (but equal) The code is as follows: var newheight = (second.offsetHeight > first.offsetHeight) ? second.offsetHeight :
4
12641
by: Henning N?rg?rd | last post by:
I'm working as software developer mostely om SQL-server platform. On SQL-server we are using a lot of "Computed Columns" Does anyone know if that is possible to do in DB2 too ? I mean - define a column, based on SQL-query in database. And how - do i do - would like a practic example if possible. /Henning
3
1979
by: Raymond Du | last post by:
Hi, Can I have computed columns in a datagrid? If yes, how? TIA
0
1253
by: am72de | last post by:
Hi all, I have two identical DataTables. One of the columns is a computed one. With a DataReader I try to copy the DataRows from one table to the other, but I get an InvalidOperationException, because calculated columns can not be set. Does anyone know a solution to work around this behaviour, for example how to exlude this column from the copy process (without removing it from the table)? Thanks in advance
7
5793
by: Aamir Mahmood | last post by:
Hi All I have DataTable object. Is there a way that I can know which fields (columns) in the table are computed. Apparantly the DataTable.Columns returns all columns both computed and other. Any help would be appreciated.
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.