473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rookie question about query/View

I have much MSACCESS expeience and am new to SQL so here goes...

I am trying to create calculated fields in a view, but can't seem to
more complex calculations to work.

I can create a new field which does simple arithmetic on two other
fields and rename it so it becomes part of the new view to be queried
by other views, but when I use more complicated constructs I can't
seem to get them to work.

For starters:

How do you create a new field that has a number based on an IF
construct based on another field.

Example:
field1 has state abbrevs and field 2 should have a "1" if field1="NY".
In access I do field2:IIF(field1="NY",1,0),
How do I accomplish this in MS SQL.
Can it be done in the view?

Thanks,
Brad
Jul 23 '05 #1
7 1330
Brad look up the "Case" comand in the books on line, that should do
what you want...

Greg

Jul 23 '05 #2
Greg,
Thanks for the answer,
I agree that the case command is the best for my example, but that
example was just a way of giving an idea of what I can't get to work.
Can the case command be entered in the view grid?
Does it have to be entered in the sql window?

I am familiar with the case command and others, but it's not clear to
me where I enter these commands.
The IF construct should work also (even though it's not the easiest or
most efficient for the example I gave), but I could not get it to
work.

In MSACCESS you enter the iif and other functions right in the grid.

I feel like I'm doing something real basic that is wrong, like
entering it in the wrong area. I have tried entering commands other
than simple equations in the grid and in the sql window with various
error messages as my ultimate result.

Any ideas.
THanks,
Brad

"gc*****@aspenres.com" <gc*****@aspenres.com> wrote:
Brad look up the "Case" comand in the books on line, that should do
what you want...

Greg


Jul 23 '05 #3
Stu
In MS Access, write a qury that uses an IIF command, and then flip to
the SQL view from the dropdown. This should show you the SQL syntax
for entering a command; CASE is similar.

SELECT field1, field2=CASE WHEN field1='NY' THEN 1 ELSE 0 END
FROM table
Hope that helps,
Stu

Jul 23 '05 #4
Thanks Stu,
Can I just put the case statement into the grid in MS SQL?
I can't seem to get th egrid to work, or should I not be using the
grid.

Brad

"Stu" <st**************@gmail.com> wrote:
In MS Access, write a qury that uses an IIF command, and then flip to
the SQL view from the dropdown. This should show you the SQL syntax
for entering a command; CASE is similar.

SELECT field1, field2=CASE WHEN field1='NY' THEN 1 ELSE 0 END
FROM table
Hope that helps,
Stu


Jul 23 '05 #5
Stu
If you're talking about the grid in Enterprise Manager, try to wean
yourself off of that as quickly as you can. It limits your flexibility
in writing clean SQL statements. I don't use it, and so I'm not sure
how to write a CASE statement in it, but I belive you can write it
directly in it.

You may want to to try writing a simple select statement using the
grid, and then adding the case statement to the SQL statement, and then
flip back to the grid to see how it gets interpreted.

Stu

Jul 23 '05 #6
Thanks Stu,
My experimentation has found exactly that.
The grid will not support case statements, so you have to write them
directly in the sql window.
I was able to get my statements to work pretty well once I figured out
how the landscape was different than access.

Access does hold your hand a bit more and it's going to take some time
to get used to writing from scratch.

Thanks again.
Brad
"Stu" <st**************@gmail.com> wrote:
If you're talking about the grid in Enterprise Manager, try to wean
yourself off of that as quickly as you can. It limits your flexibility
in writing clean SQL statements. I don't use it, and so I'm not sure
how to write a CASE statement in it, but I belive you can write it
directly in it.

You may want to to try writing a simple select statement using the
grid, and then adding the case statement to the SQL statement, and then
flip back to the grid to see how it gets interpreted.

Stu


Jul 23 '05 #7
On Wed, 15 Jun 2005 02:16:11 GMT, bm***************@bmegroup.com wrote:
Thanks Stu,
My experimentation has found exactly that.
The grid will not support case statements, so you have to write them
directly in the sql window.


Hi Brad,

I'd go one step further, and tell you not to use Enterprise Manager for
writing queries at all. Instead, use Query Analyzer (a tool much better
suited for the job) and use EM for what it is good at (managing backups,
restores, maintenance schedules, replication, etc.)

http://www.aspfaq.com/show.asp?id=2455

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #8

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

Similar topics

10
by: William S. Perrin | last post by:
I'm a python rookie, anyone have and suggestions to streamline this function? Thanks in advance..... def getdata(myurl): sock = urllib.urlopen(myurl) xmlSrc = sock.read() sock.close() ...
11
by: Don Bruder | last post by:
Got a stumper here. I imagine that for someone experienced in C++, this is too pathetic for words. For a rookie, using this project as a sort of "midterm exam" in his self-taught "how to program in...
6
by: bigjmt | last post by:
Sorry to bother you guys with what I though would be an easy task. I have a table in my database were I would like one of the rows to increment a number for each row. I want the first row to start...
5
by: Sue | last post by:
I wrote a script that uses the sp_refreshviews. The script will be part of a larger one that is automatically run in multiple databases where different views exist. Question: My understanding...
3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
14
by: GabrielESandoval | last post by:
I need to make a registration page for a community service volleyball tournament our organization is doing. I am VERY NEW to ASP. Would the easiest way to make it be just doing it on frontpage...
3
by: Dst | last post by:
Hi i'm trying to make a very simple web site using visual studio 2005. I'm completely noob at this so i need some pointers to get me started. As i understand frames should not be used in...
0
by: webgirl | last post by:
I'm relatively new to SQL Server & looking for some guidance, if possible. I've been reading lots of different things & am a bit confused about some basics. I have an Access Project with SQL...
3
by: KNN | last post by:
Hi I have some tables with hidden attribute set to 1. In the query desgn view , I do not see these tables as expected. But, If I choose the query wizard to create a new query, then i do see...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.