|
Hi. I am creating an application that uses sqlserver and asp.net c#. I need to create a trigger that inserts data into a table 30 days before an expiry date field in another table. I have created the trigger but dont know how to implement the dates? Any suggestions would be appreciated.
|
|
|
|
|
Does the date go in when the "expiry date" column is populate or do you want it to go in 30 days before the date?
|
|
|
|
|
What you are describing is not a trigger spit but a JOB, the job would call a proc that checks for expiry dates 30 days away and insert the appropriate record. You would schedule the JOB to run daily.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks for the reply. I had a feeling a trigger would be difficult or impossible to implement in this way.. Not sure how to create this job tho. Any pointers would be appreciated?
|
|
|
|
|
I already have a table with an appointment date entered. I need to update another table 30 days before before this appointment date. Thanks
|
|
|
|
|
Create a stored procedure that does the following
Get the expiring records
insert the relevant data into the target table.
In SSMS create a Job that calls the stored proc
schedule the job to run every day
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks I'll give it a try!
|
|
|
|
|
I am new to ssis. I Created on pakcage which loops excel fils(.xls) of one folder and extracts to database.
I placed Excel files in one folder (like C:\Documents and Settings\username\My Documents\Temp). The Sqlserver2005 server located on another machine (where i need to dump the data from excel to this destination server.)
I am running package on my local machine. When i run it is giving below error at Excel Source of Data Flow task.
SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "Excel" failed with error code 0xC0202009.
Please help me out.
Thanks,
Ravikiran
|
|
|
|
|
My usual attempt to resolve a sql error is to drop the error message into google[^] - seems like it is a common problem.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
In DB2, i have used XMLAGG built in function in order to convert Rows to Column String Concatenation. Since lot of records are available in the table, performance wise it was too slow. Whether any user defined function is available for DB2 for string concatenation.
Thanks in Advance.
|
|
|
|
|
EmpID Leave_Year Taken Credit Balance
435 2014 0 22 22
435 2013 10 22 12
435 2012 24 22 0
435 2011 20 22 2
435 2010 23 22 0
435 2009 21 22 1
I want to Update this table Balance column value with the Next row Balance column value
eg: Leave_Year 2011, Balance value (2) Update with Leave_Year 2012 Balance Value (0)
0 - 2 = -2 should get in 2011 Balance column, use with this where condition, where Next row (2012) Taken>0
How to write Update sql for this
|
|
|
|
|
Can you explain more in details your case?
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hi,
Check the Script
SELECT M.ID,(ROW_NUMBER() OVER(PARTITION BY M.EmpID ORDER BY M.EmpID)) 'RowNumber', M.EmpID, M.Leave_Year, M.Taken, M.Credit,
(SELECT SUM((ISNULL(Balance,0.0))
FROM Table_Name WHERE ID<=M.ID AND EmpID=M.EmpID)
FROM Table_Name M
ORDER BY M.EmpID
|
|
|
|
|
I wouldn't do that. It's against the "Rules" of normalization. You don't want to make a row dependant on another row in the same table.
Think of all the fuzz to update the table when you find out someone inserted some wrong data last year, or when HR decides to change the rules (quite probable actually).
So you should make a query that gets you the result you want instead.
Hint, checkout ROLLUP .
For example:
SELECT EmpID,
CASE WHEN (GROUPING(Leave_Year) = 1) THEN 'Total Balance'
ELSE ISNULL(Leave_Year, 'UNKNOWN')
END AS Leave_Year,
SUM(Balance) AS Balance
FROM MyTable
GROUP BY EmpID, Leave_Year WITH ROLLUP
I haven't tested this code, but it should give you an idea.
I also assumed SQLServer, Different Databases have different syntax. Use Google.
Be excellent to each other. And... PARTY ON, DUDES!
Abraham Lincoln
|
|
|
|
|
Several screens (or one very functional one) to view the data in a variety of ways like by Phase, by ESXHost, by Application.
I think if we have several drop downs for filtering then that would work; so I can choose Phase 1, to show only the databases that will be migrated in Phase 1, then I can choose some other criteria and the screen shows a subset of data etc.
3. The Pre-requisites and Post-Migration checks should show whether the Phase or database migration is ready to start or is ok to complete.
|
|
|
|
|
Dear all,
I require your opinion on what approach is good and/or practical for the following scenario.
There is a web application which queries data from SQL server.
For example:
Users report to a manager
1. The process by clicking a button is finding who reports to me (manager)
2. So there is a stored procedure written to find the users reporting to the manager
Now, there is a report (rdlc on the web server displayed via reportviewer control) which takes the manager as an input to generate report data for the staff members reporting to that manager.
The stored procedure for this report uses existing stored procedure (as in step 2 above) to find the staff members reporting to the manager and then generate required data.
My question is:
1. Is this the right way of doing this
2. Is there a need to develop a separate SQL view just for this report
3. What would be the best approach on doing this.
Please help.
Thanks
Regards,
Nayan
|
|
|
|
|
I don't see any issues with this approach, the dedicated view may be useful if reconciliation is required or you are going to use an OLAP system but not for you current requirements.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you very much.
I just needed a clarification for not under-estimating my decision over my superior.
Thank you very much.
|
|
|
|
|
Hi all. I have run into a problem with inserting values into table.
I have 2 tables: PUBLISHER with fields: PUBLISHER_CODE (Primary Key) and PUBLISHER_NAME. BOOK table fields: PUBLISHER_CODE (Primary Key and Foreign key to PUBLISHER table) and TITLE.
The user enters bookCode and publisherName into 2 textboxes
Here is the code for inserting:
"INSERT INTO BOOK (TITLE) VALUES(@bookCode)";
"INSERT INTO PUBLISHER (PUBLISHER_NAME) VALUES(@publisherName)";
When running programme, the PUBLISHER table generates a new PUBLISHER_CODE (Primary Key) and publisherName inserted.
Now problem is for the BOOK table the following error appears:
"Cannot insert the value NULL into column 'PUBLISHER_CODE'", table BOOK
Why is this happening? Doesnt BOOK generate same/new PUBLISHER_CODE from PUBLISHER table since its a foreign key?
|
|
|
|
|
Member 9912091 wrote: Doesnt BOOK generate same/new PUBLISHER_CODE from PUBLISHER table since its a foreign key?
No - you have to retrieve it from the inserted publisher record. I use a stored proc for this and return the new record after it is inserted, then you can use that ID to insert the book record.
Or
Wrap the whole thing in a SQL Transaction in a stored proc and do the insert to both table at once.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Primary key value cant be null. You have to provide any value for that.
|
|
|
|
|
Bikash Prakash Dash wrote: You have to provide any value for that
No you have to provide the correct key, any key will corrupt your data.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all. I am busy writing a program, in Microsoft Visual Web Developer, and have a database was several tables. The one I am focusing on now is the ACCOUNT table. This table contains username, password and email column.
I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table, so that I can create a message saying that the entered user already exists.
I know how to do this in C# with if statements, but am really unsure with SQL, since not sure how to use it with SELECT.Thanks
|
|
|
|
|
Member 9912091 wrote: I want to compare a username entered into a textbox with the existing usernames in the ACCOUNT table
SELECT 1
FROM Account
WHERE Username = @Username Returns 1 of the username exists
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks! 
|
|
|
|