473,944 Members | 2,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

formula column

Hi,
I would like to create a calculated column using the formula
section for a table. I am having some trouble doing this.

The table's name is ReportParameter . The calculated column's name is
tbcalculatedcol umn and tb1 and tb2 are boolean columns in the table.
I would like to use an If then statement such as the following (in
psuedo code):

If tb1 = 1 then tbcalculatedcol umn = 1
Elseif tb2 = 1 then tbcalculatedcol umn = 2
Endif

Thanks for the help,
Bill
Jul 20 '05 #1
6 12661
Hi

Maybe something like:

CREATE TABLE MyTable ( tb1 bit, tb2 bit, tbcalculatedcol umn AS CASE WHEN
tb1 = 1 then 1
WHEN tb2 = 1 then 2
END )
INSERT INTO MyTable ( tb1, tb2 ) VALUES ( 1,1 )
INSERT INTO MyTable ( tb1, tb2 ) VALUES ( 1,0 )
INSERT INTO MyTable ( tb1, tb2 ) VALUES ( 0,1 )

SELECT * FROM MyTable
/*
tb1 tb2 tbcalculatedcol umn
---- ---- ------------------
1 1 1
1 0 1
0 1 2
*/

John
"Billy Cormic" <bi**********@h otmail.com> wrote in message
news:dd******** *************** ***@posting.goo gle.com...
Hi,
I would like to create a calculated column using the formula
section for a table. I am having some trouble doing this.

The table's name is ReportParameter . The calculated column's name is
tbcalculatedcol umn and tb1 and tb2 are boolean columns in the table.
I would like to use an If then statement such as the following (in
psuedo code):

If tb1 = 1 then tbcalculatedcol umn = 1
Elseif tb2 = 1 then tbcalculatedcol umn = 2
Endif

Thanks for the help,
Bill

Jul 20 '05 #2
> I would like to create a calculated column using the formula
Why? Why not just put a CASE expression in a query or view rather than
create an extra redundant column.
tbcalculatedcol umn and tb1 and tb2 are boolean columns in the table. There is no Boolean data type in SQLServer. You mean a numeric column
(presumably BIT).

--
David Portas
------------
Please reply only to the newsgroup
--

"Billy Cormic" <bi**********@h otmail.com> wrote in message
news:dd******** *************** ***@posting.goo gle.com... Hi,
I would like to create a calculated column using the formula
section for a table. I am having some trouble doing this.

The table's name is ReportParameter . The calculated column's name is
tbcalculatedcol umn and tb1 and tb2 are boolean columns in the table.
I would like to use an If then statement such as the following (in
psuedo code):

If tb1 = 1 then tbcalculatedcol umn = 1
Elseif tb2 = 1 then tbcalculatedcol umn = 2
Endif

Thanks for the help,
Bill

Jul 20 '05 #3
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in
your schema are. Sample data is also a good ideas, along with clear
specifications.
The table's name is ReportParameter . <<
That is not a table name; a table is an entity or a relationship. It
is also too vague to be a data element. You need to read a book about
database design.
The calculated column's name is "tbcalculatedco lumn" ...<<
Please tell me that "tbl-" is not a silly redundant prefix; and there
is always a better name than "calculated_col umn" for a calculated
column -- what extactly did you you compute? Interest? discounts? To
be is to be something in particular; to be nothing in particular is to
be nothing.
and tb1 and tb2 are boolean columns in the table. <<


There are no BOOLEAN variables in SQL; it would destroy the 3VL. Look
up the CASE expression in any pf the books on SQL you clearly have
never read.
Jul 20 '05 #4
> There are no BOOLEAN variables in SQL; it would destroy the 3VL.

Aren't Booleans defined in SQL99?
Jul 20 '05 #5
Yes. Joe goes into denial when confronted with SQL99 ;-)

--
David Portas
------------
Please reply only to the newsgroup
--

"Christian Maslen" <ch************ **@techie.com> wrote in message
news:b9******** *************** *@posting.googl e.com...
There are no BOOLEAN variables in SQL; it would destroy the 3VL.


Aren't Booleans defined in SQL99?

Jul 20 '05 #6
>> Joe goes into denial when confronted with SQL99 <<

So does everyone else who worked on the draft documents :)

They had to re-define the foundation to get them into SQL-99 and this
is oneof many reasons nobody is gallopping to SQL-99. The US
government requires SQL-92 and refers to it as "a standard in
progress" in their bid forms.

The problem is that a data type in SQL must be NULL-able; a NULL
doesnto have a data type itself, but holds a place for a value which
may or may not be determined later.

1) The fundamental rule of a NULL is that it propagates.

2) The fundamental rule of 3VL is that your have TRUE, FALSE and
UNKNOWN as the only possible values.

These fundamentals don't go together if you can have a column with a
3VL datatype. The "solution" was to make NULL = UNKNOWN but only in a
BOOLEAN column and then worry about null propagation. This screws up
3VL operators in some pretty awful ways that can drive an SQL engine
nuts:

FALSE OR UNKNOWN = UNKNOWN -- definition of OR
FALSE OR NULL = NULL = UNKNOWN -- null propagation
TRUE OR UNKNOWN = TRUE -- definition of OR
TRUE OR NULL = NULL = UNKNOWN -- null propagation

likewise,

TRUE AND UNKNOWN = UNKNOWN -- definition of AND
TRUE AND NULL = NULL = UNKNOWN -- null propagation
FALSE AND UNKNOWN = FALSE -- definition of AND
FALSE AND NULL = NULL = UNKNOWN -- null propagation
Jul 20 '05 #7

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

Similar topics

2
6538
by: Doug Baroter | last post by:
Hi, I'm on SQL Server 2000, say, I have a table named , how I find if there is any column which has a formula in it? In other words, how to identify formula column programmatically? I've looked at information_schema.columns view for clue but to no avail. Thanks.
1
2141
by: Venkat | last post by:
HI, I have a problem in formula column. I have 8 1 bit varibles in a table for ex: Flag1, falg2, flag3 ...Flag8 Now I want to create another variable as a small integer and copy all the flgas to that field. For ex: (flag1 << 0x80) | (flag2 << 0x40) | ..... | flag8
3
3332
by: Max | last post by:
Hi, I am trying to convert string entered in a field to uppercase using its formula property. I know it can be done using trigger but still I want to use formula property to achieve the same. Any help will be greatly appreciated. -Max
1
2328
by: James M via SQLMonster.com | last post by:
Hi, I'm trying to count field login totals for users which updates another field in another table. Which is the most efficient method? I don't want to use a standard query as it will take too long if there are 1000 users per company each with 1000 plus logins. I was thinking in terms of either a function, or a formula (using the built- in formula field within mssql).
1
2692
by: Dim | last post by:
Hi, need some help/idea... I have data table in Excel(about 30 columns) and it's getting too big (over 65K) so I need to move it to DB (MS Access is the choice) one of the columns (for example column1 in DataTable has a string (for example AAA, ABC or BCA, etc) and i also have lookup table in excel with formulas which contains a business rule for one of the columns (column35) on how to calculate: for example for AAA the calculation would...
1
1246
by: Roy | last post by:
Ok, here's my problem and I'm a first year webbie, so you'll have to bear with me. I'm converting some Access reports over to a .NET website. It's your typical Access cluster$#@$ (pardon my French). The report is essentially a single row with 10 columns. Each column holds data mostly independent of the other columns as shown here: col1 --data is pulled from table "x" col2 --data is pulled from table "y" col3 --data is pulled from table...
1
2214
by: joshtaylor | last post by:
Hi guys, I am new to all of this stuff so please bare with me. I will try to explain this as simply as I can. I have 2 tables.. Table1 and Table2 they are linked using both the STOCKCODE and SUPPLIER fields. In Table 1 is the STOCKCODE, LENGTH AND SUPPLIER fields (there are others but these are the 3 that I need to use) In Table2 is STOCKCODE, SUPPLIER and SUPPLER_MASS. What I want to do is put a calculated column into Table2. The formula I...
1
3661
by: LimaCharlie | last post by:
Good day! What is the syntax on calling a function from a column formula in an MS SQL table. I created a table, one column's value will be coming from a function. And at the same time, I will pass parameters to the function. How do I do this? Is this correct? SELECT dbo.FunctionName() But i can't save the table, "Error validating the formula".
1
5078
by: barnzee | last post by:
Hi all, newbie here, but having a go I am trying to build a stock watchlist in excel 2007 with a dynamic link to a DDE server (paid for from a broker).There is no add-in or plug-in, I just CTL ALT & drag each code from a watchlist in the program I am using and place it in a cell in excel, however can only choose one data field at a time. There are 14 data fields and over 150 codes in my list which makes 2100 cells. (My guess is about 3 days...
0
10147
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9973
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
10677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9870
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...
1
8238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7399
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
6093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4924
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

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.