Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Monday, March 19, 2012

Automatic insert with a variable

Hi everyone, I'm very new at SQL so my knowledge is very limited. Therefore, all the details/examples I need to know to accomplish this would be greatly appreciated. Anyway, I was wondering if there was a way to create a job (that will run every week) that inserts a record into a database...which I've figured out how to do using the "Job" area in SQL EM, in fact, here's what I have -

INSERT INTO ProjMan (CustID, EntryDate, DueDate, DueTime, EmpEntered, Tech, ProjDesc, ProjType, Notes, IsCompleted) Values (1, '12/10/03', '1/2/04', '1/2/04 10:00:00 AM', 'Jamie', 'Jamie', 'Lito Report - auto insert','Job', 'no notes', 0)

But as you can see, my dates (and time) is 'hard-coded' in there. So my question is this: is there a way to automatically grab the current day and use it? Better yet, I would like this job to run every Sunday and actually have the date be for the coming up Tuesday, so i would need to add 2 days to the variable also if possible. If this isn't possible, I can just have the job run early Tuesday morning and insert it as the current day.

Thanks in advance for the help.Check BOL for functions getdate(), dateadd(), datepart(), etc.|||Thanks alot. I'll check it out.

Sunday, February 12, 2012

Auto insert a variable number of records?

I have the following situation; I have one table (tblA) in which a new record just has been inserted. Once this insert is completed successfully, I want to insert a variable number of records into another table (tblB). The primary key of tblA is being used inside tblB as one of the columns in each insert. I’ve already been able to transfer the primary key, generated by the insert for tblA, pretty easy. But to make things a bit more complicated, the variable number of records to add is being decided by the outcome of a query based on an entry inside tblA (after the insert) and this is then being run on another table (tblC). The SELECT statement from tblC combined with the Select parameter from tblA will then decide how many records I have to insert. Sorry for the (perhaps) confusing way of writing this down, but I’ve been struggling with this for a couple of days now and I really need to get it working. Anybody who can help?

Thanks in advance,

Sunny Guam

Can't you put all operations in a trigger on tblA? Put the SELECT command to tblC before INSERT to tblB so that you can dynamically build INSERT commands to tblB.|||

Thanks for the advice, but at the risk of sounding dumb; I'm not familiar with triggers and how to set them up within SQL 2005. Can you give me an example perhaps?

|||

Here is an example:http://forums.asp.net/thread/1281234.aspx

You can start from hereEnforcing Business Rules with Triggers