473,790 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Status Field after Expiry Date

Consider the following table

Customer
custId char(10)
accountExpiryDa te datetime
accountStatus bit

Now, I want to update the accountStatus to False as soon as the
current date becomes accountExpiryDa te.

I think it can be done using "SQL Agent" but my webhost doesnt provide
me access to that. I have access only to the Query Analyzer.

Thanks
Shane

Mar 26 '07 #1
12 4703
Shane,

If you have access to the database from your workstation (and it seems as
though you do), you can create a batch file using osql and schedule it to
run nightly (or more often) using Windows scheduled tasks.

osql -S servername -U userid -P password -q "update Customer set
accountStatus = 0 where accountExpiryDa te < CURRENT_TIMESTA MP and
isnull(accountS tatus,1) = 1"

-- Bill

<sh************ @gmail.comwrote in message
news:11******** *************@r 56g2000hsd.goog legroups.com...
Consider the following table

Customer
custId char(10)
accountExpiryDa te datetime
accountStatus bit

Now, I want to update the accountStatus to False as soon as the
current date becomes accountExpiryDa te.

I think it can be done using "SQL Agent" but my webhost doesnt provide
me access to that. I have access only to the Query Analyzer.

Thanks
Shane

Mar 26 '07 #2
>Consider the following table <<

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it. Here is my guess, unsupporteed by anythign you told us

CREATE TABLE Customers -- plutal names for sets, please
( cust_id char(10)
accountExpiryDa te datetime
accountStatus bit

Now, I want to update the accountStatus to False as soon as the
current date becomes accountExpiryDa te.

I think it can be done using "SQL Agent" but my webhost doesnt provide
me access to that. I have access only to the Query Analyzer.

Thanks
Shane

Mar 27 '07 #3
>Consider the following table <<

Where is it? Please post DDL, so that people do not have to guess
what the keys, constraints, Declarative Referential Integrity, data
types, etc. in your schema are. Sample data is also a good idea, along
with clear specifications. It is very hard to debug code when you do
not let us see it. Here is my guess:

CREATE TABLE Customers
(cust_id CHAR(10) NOT NULL PRIMARY KEY, --wild guess
acctexpiry_date DATETIME NOT NULL,
..);

Notice I dropped the redundant BIT column. Some newbie actually used
a proprietary, low-level BIT data type. You need to fix that at once
and teach the guy that SQL has no BOOLEAN data types -- that is just
sooooo fundamental!
>Now, I want to update the account_status to FALSE as soon AS the current date becomes accountexpiry_d ate. <<
Just like you would do this in a punch card system 50 years ago!
Running updates to physical storage every day? You are missing the
fundamental concepts of RDBMS in this design. Each row of a table is
a fact that should stand by itself. Use a VIEW not an assembly
language bit flag!!

CREATE VIEW ActiveCustomers (..)
AS
SELECT cust_id, acctexpiry_date , ..
FROM Customers
WHERE CURRENT_TIMESTA MP < acctexpiry_date ;

And then you need to consider how much history and account status
codes you want. Do you need to design an acct_status code? Etc.


Mar 27 '07 #4
--CELKO-- wrote:
Notice I dropped the redundant BIT column. Some newbie actually used
a proprietary, low-level BIT data type. You need to fix that at once
and teach the guy that SQL has no BOOLEAN data types -- that is just
sooooo fundamental!
Yes and no. It's optional, so *of course* every major implementation
deals with it differently.

http://troels.arvin.dk/db/rdbms/#data_types-boolean
CREATE VIEW ActiveCustomers (..)
AS
SELECT cust_id, acctexpiry_date , ..
FROM Customers
WHERE CURRENT_TIMESTA MP < acctexpiry_date ;
If the expiration date is "expires after this date" rather than "expires
on this date", then change the WHERE clause to

WHERE CURRENT_TIMESTA MP < DateAdd(dd, 1, acctexpiry_date );
Mar 27 '07 #5
(sh************ @gmail.com) writes:
Consider the following table

Customer
custId char(10)
accountExpiryDa te datetime
accountStatus bit

Now, I want to update the accountStatus to False as soon as the
current date becomes accountExpiryDa te.

I think it can be done using "SQL Agent" but my webhost doesnt provide
me access to that. I have access only to the Query Analyzer.
Change accountStatus to

accountStatus AS (CASE WHEN accountExpiryda te < getdate()
THEN convert(bit, 1)
ELSE convert(bit, 0)
END)

--
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
Mar 27 '07 #6
Thanks to CELKO for being so critical.

1) It is pretty obvious that this cannot be the design for my actual
table, this was to simplify the post.
CREATE TABLE Customers -- plutal names for sets, please
( cust_id char(10)
Thanks again from the "newbie"

>You need to fix that at once and teach the guy that SQL has no BOOLEAN data types -- that is just sooooo >fundamental!
Did not know that.
Yes and no. It's optional, so *of course* every major implementation
deals with it differently.

http://troels.arvin.dk/db/rdbms/#data_types-boolean
To CELKO : Would want your comments on this for "MS SQL Server"
Change accountStatus to

accountStatus AS (CASE WHEN accountExpiryda te < getdate()
THEN convert(bit, 1)
ELSE convert(bit, 0)
END)
Works Great!!! However, I would go with CELKO's view solution. I have
to create a VIEW on that table anyways.
To CELKO:- You could have conveyed the message better by being a less
rude :(

Mar 28 '07 #7
>Did not know that. <<

All data types have to be NULL-able in SQL. Having a BOOLEAN type
would lead to 4 valued logic with inconsistent rules about how NULLs
propagate. And the various vendor extension do not work or port
either.
>To CELKO:- You could have conveyed the message better by being a less rude <<
I am always like this in Newsgroups, but I am very nice in person. If
I had any friends you could ask them.
Mar 29 '07 #8
--CELKO-- wrote:
All data types have to be NULL-able in SQL. Having a BOOLEAN type
would lead to 4 valued logic with inconsistent rules about how NULLs
propagate. And the various vendor extension do not work or port
either.
It seems like dropping UNKNOWN would leave a sensible set of rules:

and | T N F or | T N F not |
----+------ ---+------ ----+--
T | T N F T | T T T T | F
N | N N F N | T N N N | N
F | F F F F | T N F F | T

Am I overlooking anything?
Mar 30 '07 #9
On Thu, 29 Mar 2007 18:08:00 -0700, Ed Murphy wrote:
>--CELKO-- wrote:
>All data types have to be NULL-able in SQL. Having a BOOLEAN type
would lead to 4 valued logic with inconsistent rules about how NULLs
propagate. And the various vendor extension do not work or port
either.

It seems like dropping UNKNOWN would leave a sensible set of rules:

and | T N F or | T N F not |
----+------ ---+------ ----+--
T | T N F T | T T T T | F
N | N N F N | T N N N | N
F | F F F F | T N F F | T

Am I overlooking anything?
Hi Ed,

You've overlooked the basic rule of NULL propagation: any expression
involving NULL results in NULL. In the tables above, there are
exceptions to this rule, such as NULL AND FALSE resulting in FALSE, and
TRUE OR NULL resulting in TRUE.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Apr 5 '07 #10

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

Similar topics

3
2017
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does exist." Althought there is not selection going on, instead it is entered, I need it to match the flight in the db using the flightNo. I want all the attributes to be changed apart from the flightNo itself as it is it's associated details I need...
2
19897
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires = Date().toLocaleString(); Response.Cookies("Test").Expires = Date().toString(); Response.Cookies("Test").Expires = Date().toUTCString();
4
2859
by: ianv2 | last post by:
Hi Is the following possible using Javascript ? I would like a page to redirect to another page if the page expiry has passed. E.G. If my questionnaireform.html page had an expiry date of July 31, if I
4
10065
by: William Bradley | last post by:
I have two cells on a form. One of them is the "Production Date" and the other is the "Expiry Date". The "Expiry Date" is 183 days after the "Production Date." On an Excel spreadsheet, the "Expiry Date" is automatically entered, when the "Production Date" is entered. To do this the "Expiry Date" cell carries the following formula: "=A15+183". I would like to be able to do the same on an Access Form, with the results written to the...
2
3525
by: William Bradley | last post by:
"Marshall Barton" <marshbarton@wowway.com> wrote in message news:9as9lvgpnp783kogctb88c8giaepb5uf6g@4ax.com... > William Bradley wrote: > >I have two cells on a form. One of them is the "Production Date" and the >other is the "Expiry Date". The "Expiry Date" is 183 days after the >"Production Date." > >On an Excel spreadsheet, the "Expiry Date" is automatically entered, when >the "Production Date" is entered. To do this the "Expiry...
3
9268
by: hasanainf | last post by:
Hi all, What will be the best database design for an inventory control that uses expiry date for its products. Over a period of time, a particular product will have many expiry date and that one particular expiry date could have multiple products I am thinking of two approaches not knowing which one to go for. First design is of one product having many expiry dates (a one to many
3
2009
by: Melon via AccessMonster.com | last post by:
If anyone could take a look at this, I could do with the help. Im running into 2 problems with my db. 1) I have a members section in my db. If a member is selected as senior, all fields apply to him, if a member is selected as junior, other fields don't apply and I need to be able to hide them. 2) I have a date joined field, there is an expiry date field, which is date
11
1849
by: John | last post by:
Hi I had a working vs 2003 application with access backend. I added a couple fields in a table in access db and then to allow user to have access to these fields via app I did the following; 1. Regenerated the data adapter sqls by running the data adapter wizard and pasting the resulting code into my app. 2. Deleted the data adapter correspond to the relevant access table from the
0
1702
by: jon | last post by:
Hi there, I'm brand new to Access and may be trying to do too much too soon, but I wanted to get some expert advice on how the best way to go about what I am trying to accomplish would be. I am trying to modify the Microsoft Template at the following address (http://office.microsoft.com/en-us/templates/TC012186931033.aspx?CategoryID=CT101426031033) to work as an issues tracker that imports and updates the issues from a SQL 2005...
0
9511
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
10412
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...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10142
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
9986
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
6769
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
5422
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
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.