Click here to Skip to main content
       

Database

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
QuestionData ClashesmemberBram van Kampen21 May '13 - 15:04 
Hi,
 
I am using VS 2012 Free Edition (et al)
 
I am contemplating using this for the next version of 25 year old successfull software. We need to update various tables in a single transaction. This transaction needs to proceed in a step in which either All succeed, or None succeed. (resulting in a roll-back if any step failed) The database must deal with a high likelyhood that several terminals will at the same time try to write to the same entry in the same table. I handled this in MFC, with my own DB by giving each contentious item a serial-number, The first check for a modify-save would be if the serial number was still the same. if not, the item would be refused, and the transaction rolled back.
How does SQL handle this.
 
N.B.
 
The word 'Serial Number' seems to link to some add somewhere. Nothing to do with me! Just, Don't click it on my behalf.
 
Thankfully that link has disappeared since. TAKE NOTE IF IT HAPPENS TO YOU. The term 'Serial Number' turned into a link to some mobile phone sellers. Its gone now.
Smile | :) Smile | :)
Bram van Kampen

AnswerRe: Data ClashesmemberDavid Mujica22 May '13 - 2:26 
Maybe I don't fully understand the problem, but SQL Server will handle "transactions" the same way. You declare the start of a transaction "Begin Transaction", do your stuff, then either "Commit" or "Rollback" the activity.
 
SQL server can automatically generate "serial" numbers for you. Look into the column data-type known as "Identity Column".
 
Did that answer your question?
GeneralRe: Data ClashesmemberBram van Kampen23 May '13 - 15:55 
Thanks,
 
I've since learned about the existence of 'Begin-End Transaction' Can you give me a link to a page explaining what it does and how it works?
 
Regards,#
Smile | :)
Bram van Kampen

QuestionStored Procedures SQL Servermemberdamokk21 May '13 - 1:11 
I have created a stored procedure which lists all customers that have 7 days left on their membership.
----------
create proc spGetMemReminder
as
select users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
-------
I would like to insert this list into another table automatically. How do I achieve this? any suggestions appreciated. Thanks
AnswerRe: Stored Procedures SQL Servermemberscottgp21 May '13 - 2:37 
Do you mean like this - http://sqlserverplanet.com/tsql/insert-stored-procedure-results-into-table[^]?
Scott
AnswerRe: Stored Procedures SQL Servermemberdjj5521 May '13 - 2:58 
Just use an insert:
CREATE PROCEDURE spGetMemReminder
AS
INSERT INTO YourTableNameHere (FullName, ExpiryDate)
SELECT users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where expiryDate = CAST(DATEADD(day, 7, getdate()) AS DATE
if expiryDate is a date column it is better to do date compare than to convert both sides.
GeneralRe: Stored Procedures SQL Servermemberdamokk21 May '13 - 4:14 
thanks!
AnswerRe: Stored Procedures SQL ServerprofessionalMycroft Holmes21 May '13 - 3:19 
Use an insert statement, that is not why I am posting a reply.
 
There are many ways to compare dates, comparing string (varchar) is probably the worst possible method. Do some research into the datetime object, you could have used datediff or dateadd neither of which require a convert.
 
Never underestimate the power of human stupidity
RAH
GeneralRe: Stored Procedures SQL Servermemberdamokk21 May '13 - 4:15 
ok will do. thanks!
AnswerRe: Stored Procedures SQL ServergroupArun Vasu22 May '13 - 19:55 
Hai.... You can do it by table varible.
 
create proc
spGetMemReminder
as
select users.fullname, membership.expiryDate from membership
inner join users on membership.uid=users.uid
where convert(varchar(10), expiryDate,105) = convert(varchar(10), (getdate() +7), 105)
end
 
GO
 
CREATE PROCEDURE InsertMember
AS
BEGIN
    SET NOCOUNT ON
        DECLARE @TABLE TABLE(fullname nvarchar(10), expiryDate datetime)
 
        insert into @TABLE
        exec spGetMemReminder
 
        insert into yourothertable
        select * from @TABLE
    SET NOCOUNT OFF
END

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid