|
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?
|
|
|
|
|
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,#
Bram van Kampen
|
|
|
|
|
|
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
|
|
|
|
|
|
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.
|
|
|
|
|
|
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
|
|
|
|
|
|
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
|
|
|
|
|
I think 'Insert into' query will help you
|
|
|
|
|
Hi All,
I have an SSIS package, which is trying to import data from a flat file in to a destination table in SQL. But the problem is not all columns in the destination table should come from flat file, there are few columns that should be filled from some other SQL Server source table.
Can we import data from a flat file and a table simultaneously into one table, is so how can we do that?
Please help me, its urgent. I am also searching but any help like code snippet, link or even a free advice is great.
Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Change your strategy to ELT, import your data into a staging table that is an exact match for the source, all varchar columns!
The use a stored proc to transform the data into your final table. This method NEVER fails in the load process because of missing columns or date formats or a number has a $ sign.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Have a five.
Be excellent to each other. And... PARTY ON, DUDES!
Abraham Lincoln
|
|
|
|
|
Dammed if I know why someone would down vote this it is a perfectly valid question - balanced.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Is Entity Framework is best choice for database creation and manipulation in Web application which is made on MVC4.
If yes then how is it ?
|
|
|
|
|
NO the best way is to roll your own DAL layer. You will then have the knowledge and control to manage your data. EF is too much of a black box for my taste.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well said: I used it on a couple of projects but have now gone back to ADO and my own DAL as it gives me more control and I don't feel that ORMs are the be-all and end-all.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
hi to all
how to union two below query
thanks in advance
SELECT
dailyAbsences.*,'غیبت' as [RowType], '0' as [RowTypeCode]
INTO
#fullPersonnelDetails2
FROM
#personnelWorkingPeriodRange personnelWorkingPeriodRange
INNER JOIN dbo.tkp_vwDailyAbsences As dailyAbsences
ON dailyAbsences.PersonnelBaseID = personnelWorkingPeriodRange.PersonnelBaseID
And dailyAbsences.StartDate >= personnelWorkingPeriodRange.StartDate
And dailyAbsences.EndDate <= DateAdd(day, 1, personnelWorkingPeriodRange.EndDate)
LEFT JOIN tkp_CalculationQueue As calculationQueue
ON dailyAbsences.PersonnelBaseID = calculationQueue.PersonnelBaseID
And calculationQueue.StartDate <= personnelWorkingPeriodRange.EndDate
ORDER BY
dailyAbsences.PersonnelBaseID,
dailyAbsences.StartDate
UNION
SELECT
'اضافه کاری' as [RowType], '1' as [RowTypeCode]
FROM
dbo.tkp_DailyStatistics dailystatistics
WHERE
dailystatistics.ActualExtraWork > dailystatistics.ExtraWork AND
dailystatistics.PersonnelBaseID = @PersonnelBaseID AND
dailystatistics.WorkingPeriodID = @WorkingPeriodID AND
dailystatistics.YearWorkingPeriodID = @WorkingPeriodYear
IF EXISTS ( SELECT * FROM tempdb..SYSOBJECTS WHERE Name = '#PersonnelWorkingPeriodRange' and xType = 'u')
DROP TABLE #PersonnelWorkingPeriodRange
|
|
|
|
|
Your 2 select statements do not have the same number of columns - union requires the 2 queries to match exactly. dailyabscence.* is not in your 2nd query.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Also using * is not advised. Technically okay but it is better to spell out the columns.
|
|
|
|
|
I think using .* is the least of his problem if he does not understand the structuring of a union query. He obviously has not even glanced at the BOL doco for union so expecting him to understand a more subtle issue of using * is probably asking a little too much.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree. I was just pointing out one of many things to look at.
|
|
|
|
|
Hi,
I would like to ask if I have a query like this:
SELECT * FROM member
which one is better to use specially performance wise, stored procedure or views?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Neither; it's fine the way it is. There may be other reasons to choose to write a view or a procedure, but performance generally isn't one of them.
|
|
|
|