473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Check Data Before Update

Hello Everybody!

I have a POLINE table on a SQL Server 2000 DB. Before I update the
record I need to check that either field, STORELOC or WONUM has data
on it. If both fields are NULL I would like to send a message letting
the user know that either fields needs data before they can save the
record. If any of the fields have data then, it is OK to save the
record.

Could you please let me know how to accomplish this? An example will
be really helpful, I can do this in Access but I do not know how to do
it in SQLServer. I was thinking using trigger but there are not really
good examples.

Thanks in Advance!

Martin
Jul 20 '05 #1
1 5287
[posted and mailed, please reply in news]

Martin (ma***********@wsidc.com) writes:
I have a POLINE table on a SQL Server 2000 DB. Before I update the
record I need to check that either field, STORELOC or WONUM has data
on it. If both fields are NULL I would like to send a message letting
the user know that either fields needs data before they can save the
record. If any of the fields have data then, it is OK to save the
record.

Could you please let me know how to accomplish this? An example will
be really helpful, I can do this in Access but I do not know how to do
it in SQLServer. I was thinking using trigger but there are not really
good examples.


The answer is that you don't do this in SQL Server.

No, get me right. You can certainly have a check for this in SQL Server:

create table POLINE (...
STORELOC some_type not null,
WONUM other_type not null,
...
constraint POLINE_CHK_STORELOC_WONUM
check (STORELOC is not null or WONUM is not
null)

This table constraint will cause SQL Server to flatly accept any rows
where both columns are NULL. If exactly one should be non-NULL the
check should read:

STORELOCK is not null and WONUM is null or
STORELOCK is null and WONUM is not null

However, this does not really meet your requirements, because the
message will not be useful to the user. To this end, you need to
do the check in the client.

There is an important difference between Access and SQL Server. Access
is both database and GUI in one, but SQL Server is only the server
side, and requires a client on the other end. (Which could be Access.)

Still constraints like these are very useful, because they can cover
up for tests that the GUI programmer failed to include, and protect
the integirty of the data.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

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

Similar topics

2
by: Doug Baroter | last post by:
Hi, DDLs and DMLs: create table #job (jobID int identity(1,1) primary key, jobName varchar(25) unique not null, jobEndDate dateTime, jobComplete bit default(0), check (( is null and = 0) OR (...
5
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
2
by: aaj | last post by:
Hi all I have a continuous bound form and on each record is a tick box. The user ticks the boxes and these boxes define the batch. for future operations before they leave the page I count...
4
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
6
by: Gari | last post by:
Hello everyone, I have two forms: FORM1 and FORM2. On FORM1 there is a check box (CHECK). When CHECK is checked, the data is updated in a YES/NO data type table (TABLE) field. On FORM2 I...
5
by: RvGrah | last post by:
I've built a small app to deploy my apps in a small domain, just for my own use when I make small updates to pass to my end users. My app uses File.Copy, and works fine except that it takes a long...
6
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I am having trouble with the binding of a check box. I have a form for editing and adding reps. I am using a bindingsource and a bindingnavigator. I have on the form an "Active" checkbox, which...
3
by: datosivakumar | last post by:
How to find out the space usage for all the databases in MS SQL thru SQL Query Analyzer? Normaly i used to view thru SQL Server Enterprise Manager Screen (view --> Taskpad) by selecting 1 db per...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.