SELECT @Kredit= Voucher_Value,
@voucher_status = Voucher_Status
FROM Voucher
WHERE Voucher_ID = @voucher_id
INSERT INTO User_Balance(AddVoucher_ID, UserId, Update_Type, Update_Date)
VALUES (@Add_id,@UserId, 'Kredit',@date)
select @last_balance = Balance
from User_Balance
WHERE UserId = @UserId and Balance = (select TOP 1 Balance User_Balance where UserId = @UserId order by Update_Id DESC)
if (@voucher_status = 'active')
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- Insert statements for trigger here
BEGIN
update User_Balance
set Balance = @last_balance + @Kredit
where AddVoucher_ID = @Add_id
update Voucher
set Sold_Date = @date
where Voucher_ID = @voucher_id
END
ELSE
BEGIN
raiserror ('Voucher is not valid',0,1)
rollback transaction
END
go
the problem is the update function is not working and the if statement always put to 'FALSE'
do you think anything wrong with the code
Hi allWe have some tables with a couple of layers of very simple views built ontop. In the table are maybe 6 columns and about 15000 records. The firstview cobines the data in the table with some other data from a lookuptable. The second view does some sorting on the first view using certaindates . They have worked fine for well over a year now.Until this morning that is... the views stopped returning the full set ofresults- even the very simple one that sits just above the table. The viewreturned the core of the data from the main table, but nothing from thelookup table.In order to get them to work we had to delete each view (using access frontend to do this), and then recreate it with exactly the same SQL text. I amguessing this causes SQL Server to recompile it. As soon as view 1 had beenrecreated it worked, but view 2 still failed, again rebuilding view 2 itstarted working.The only thing I can think of is that this morning I added 2 new fields tothe base table, but I'm sure I've done this before without any (noticable)problems.any thoughts as to why it happened would be welcome, I am a bit nervousnow...thanksAndy
- Operating System Minimum Level Requirement (Success) Messages * Operating System Minimum Level Requirement
* Check Passed
- Operating System Service Pack Level Requirement. (Success) Messages * Operating System Service Pack Level Requirement.
* Check Passed
- SQL Server Edition Operating System Compatibility (Warning) Messages * SQL Server Edition Operating System Compatibility
* Some components of this edition of SQL Server are not supported on this operating system. For details, see 'Hardware and Software Requirements for Installing SQL Server 2005' in Microsoft SQL Server Books Online.
* The current system does not meet the minimum hardware requirements for this SQL Server release. For detailed hardware and software requirements, see the readme file or SQL Server Books Online.
* Microsoft Internet Information Services (IIS) is either not installed or is disabled. IIS is required by some SQL Server features. Without IIS, some SQL Server features will not be available for installation. To install all SQL Server features, install IIS from Add or Remove Programs in Control Panel or enable the IIS service through the Control Panel if it is already installed, and then run SQL Server Setup again. For a list of features that depend on IIS, see Features Supported by Editions of SQL Server in Books Online.
- Internet Explorer Requirement (Success) Messages * Internet Explorer Requirement
* Check Passed
- COM Plus Catalog Requirement (Success) Messages * COM Plus Catalog Requirement
* Check Passed
- ASP.Net Version Registration Requirement (Success) Messages * ASP.Net Version Registration Requirement
* Check Passed
- Minimum MDAC Version Requirement (Success) Messages * Minimum MDAC Version Requirement
* Check Passed
furthermore i get error 26 when trying to create new sql server database. and while doing the SQL server surface area configuration i got this message.:
SQL Server 2005 components were found on the specified computer. Either no components are installed, or you are not an administrator on this computer. (SQLSAC) ------------------------------ Program Location: at Microsoft.SqlSac.MainPanel.FormFeatures..ctor(String machineName, Form callingForm)
HOpefully somebody out there will help me...or is this problem only appearing in sql server 2005 and would it be a better decision to install SQL server 2000...or if someone can help me rectify this problem i'll be really thankful.
We have triggers on each table in oracle database and none in sqlserver so far. But we are looking at creating triggers on sqlserver db's as well and I am trying to find the equivalent syntax for T sql..
In ORACLE, for edi_invoice column on EDI table:
CREATE OR REPLACE TRIGGER edi_trg before insert or update ON edi for each row begin
:new.EDI_INVOICE:= nvl(:new.EDI_INVOICE,' '); end /
I think in T SQL is should be like below?
CREATE TRIGGER edi_trg ON edi for insert or update as
Hi, Am having problems creating trigger. I want to have a trigger update a table (tblClaimItemID) with the value of ClaimItemID + 1 and insert this value as the primary key of tblClaimItemsDaily(to field ClaimItemID) on insert of a record into tblClaimItemsDaily (so that when data is appended to tblClaimsItems we have a unique primary key). tblClaimItemsDaily is the day sheet, so need to have another table generate the primary key since there will be multiple tblClaimItemsDaily tables open at any given time, but the key must be unique. I've been looking at deja and in my books, but they don't seem to indicate how to do this.
Here's the code. Any ideas? ------------begin code-------
CREATE TRIGGER trgClaimItemID ON [tblClaimItemsDaily] FOR INSERT,UPDATE AS
DECLARE @Item int
IF UPDATE(ClaimID) BEGIN IF @@ROWCOUNT = 1 Update dbo.tblClaimItemID SET dbo.tblClaimItemID.ClaimItemID = dbo.tblClaimItemID.ClaimItemID + 1 FROM dbo.tblClaimItemID Select @Item = dbo.tblClaimItemID.ClaimItemID FROM dbo.tblClaimItemID
i am having an issue with my trigger code i believe that i should be able to use the multiple if else statements and i just threw in an update in each begin end statement but when i check the syntax it fails
any reason why that is CREATE TRIGGER [tr_update_conveyor_interface] ON [dbo].[t_conveyor_interface] FOR UPDATE AS
-------------------------------- CREATE TRIGGER trIns_Test ON tblTest FOR INSERT AS
DECLARE @Message VARCHAR(100), @Num INT
SELECT @Num = user_id from INSERTED SELECT @Message = 'NET SEND NICK '+' Here is the new # - ' + CONVERT(VARCHAR(100), @Num) EXEC master.dbo.xp_cmdshell @Message --------------------------------
But when i insert a row into tblTest table i'am supposed to receive a NET SEND message. But its not happening if i hardcode the value @Num i.e
SELECT @Num = 321
Then i receive a message, but why this INSERTED clause does't work i'm unable to trace out.
i have configure a SSIS package in BIDS to use an Env. Var. to store the location of the .dtsconfig file for the connection to my SSIS configuration table in SQL. I than use another Env. Var. to retrieve the source conn. str. from my SQL SSIS configuration table. Once my package loads, i select a simple sql task to execute, but it comes back and says that it cannot make the connection. How does the SQLServer connection string know what password to use? This is where i'm confused. I believe it loads the connection string for my source database but it doesn't get the password. I just started working in SSIS and i'm trying to get my head around all of the dynamic options of SSIS. I appreciate your time and help.
Problem Details: package A has 1 sql execute task Env.Var. 1 stores the location of the .dtsconfig file that stores the connection data to ssis sqlserver configuration table (used to store additional package properties in sql server) Env. Var. 2 stores the connection string of my source database. package protection level set at "EncryptSensitiveWithPassword" the sql task is assigned to the source connection string,right click and execute task.
here is the error: Failed to acquire connection "source database" Connection may not be configured correctly or you may not have the right permission on this connection.
I'm executing this from within BIDS just to check that my setup is going to work.
Here are some items i've tried or troubleshoot:
1. If I roll back the 2 package Configs or disable using package configs and replace my original source connection manager and create a new connection manager than i can get the sql task to successfully execute again. It won't usually work by just disable the package configs. i had to delete the existing source connection manager.
2. create a new package trying the same steps as above.
3. change the package protection level to "encryptSensitiveWithPassword" expecting this to retain the source connection password. I tried a variety of package protection levels.
I'm sure this has been asked plenty of times before, so I'm after a link to a good answer.
I have tens of thousands of milk crates, holding dozens of different types of milk in hundreds of locations. I am used to working with objects but not databases. For this situation however I want the security of SQLServer transactions to track, for example, when a robot moves a crate from one location to another.
I am thinking of using SQLServer as a store. On startup I want to get my ecosystem of objects out of the store. While I am running, I'll just use objects. When I change an object property I want it to securely persist. I don't want to snapshot the whole menagerie of object states, just update the values that changed. Which will sometimes include the addition or deletion of objects. How do I do this? Is there an example somewhere that does this (or approximately this)?
I use VB and have Visual Studio 2005. (Which, by the way, is stunning. I thought all that "you will use less time and code more and better" talk was just hype. But its for real. Amazing product.)
Hi,I have a trigger in mysql as below...I need to change it into sqlserver.I am unable to find replacement to 'for each row'.Can u please let me know how can we change this trigger into sqlserver format. CREATE TRIGGER TGR_ENTITY_TYPE_ON_ADD BEFORE INSERT ON ENTITY_TYPE FOR EACH ROW SET NEW.DATE_ADDED=NOW(), NEW.DATE_MODIFIED=NOW(); Thanks in advance, MLR
Hi, I am trying to concatenate the columns (PrevEmp01, PrevEmp02, PrevEmp03, PrevEmp04, PrevEmp05) into column (ft) using trigger: CREATE TRIGGER [tg_prevemp_ft_update] ON [tStaffDir_PrevEmp] FOR INSERT, UPDATEASUPDATE tStaffDir_PrevEmp SET ft = PrevEmp01 + ' ' + PrevEmp02 + ' ' + PrevEmp03 + ' ' + PrevEmp04 + ' ' + PrevEmp05 I would expect the (ft) column will be populated accordingly regardless if any of the columns are (Null).But the Trigger will only work when all the 5 columns are populated. If one of the column is (Null), the (ft) column will be (Null) too.Please advise. Many Thanks.
--If Exists (Select 1 From Inserted) And Exists (Select 1 From Deleted) set @var_db_contract =(SELECT a.db_contract FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) IF @var_db_contract IS NOT NULL BEGIN SET @var_db_contract=(SELECT a.db_contract FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_cqe=(SELECT a.cqe_numb FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_pc=(SELECT a.pc_code FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_item=(SELECT a.item_no FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_fiyr=(SELECT a.fy_item FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) set @var_chk ="Y" END ELSE BEGIN SET @var_db_contract=(SELECT a.db_contract FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_cqe=(SELECT a.cqe_numb FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_pc=(SELECT a.pc_code FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_item=(SELECT a.item_no FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_fiyr=(SELECT b.fy_item FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) set @var_chk="N" END SET @var_amt_paid=(SELECT a.amt_paid_item FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_amt_old=(SELECT b.amt_paid_item FROM inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no ) SET @var_amt_result =ISNULL(@var_amt_paid,0) - ISNULL(@var_amt_old,0)
SET @var_amt_ret = (SELECT a.amt_ret_item from inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no) SET @var_amt_ret_old=(SELECT b.amt_ret_item from inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no) SET @var_amt_ret_result = isnull(@var_amt_ret,0) - isnull(@var_amt_ret_old,0)
SET @var_quant_new = (SELECT a.quantity from inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no) SET @var_quant_old =(SELECT b.quantity from inserted a,deleted b where a.db_contract = b.db_Contract and a.cqe_numb = b.cqe_numb and a.pc_code = b.pc_code and a.item_no = b.item_no) SET @var_quant_result = isnull(@var_quant_new,0) - isnull(@var_quant_old,0) SELECT @item_new = new_item FROM VALID_ITEM WHERE DB_CONTRACT = @var_db_contract AND PC_CODE = @var_PC AND ITEM_NO = @var_ITEM
UPDATE ae_contract set amt_paid_contr = isnull(amt_paid_contr,0) +@var_amt_result, amt_ret_contr = isnull(amt_ret_contr,0) + @var_amt_ret_result where db_contract = @var_db_contract
IF @item_new = 'N' BEGIN update vendor set used_amt = isnull(used_amt,0) + @var_amt_result + @var_amt_ret_result where db_vendor = (select gen_contr from ae_contract where ae_contract.db_contract=@var_db_contract); END UPDATE enc_det set amt_paid_fy = isnull(amt_paid_fy,0) + @var_amt_result, amt_ret_fy = isnull(amt_ret_fy,0) + @var_amt_ret_result where db_contract = @var_db_contract and pc_code = @var_pc and fy = @var_fiyr
UPDATE valid_item set tamt_ret_item = isnull(tamt_ret_item,0) + @var_amt_ret_result, tamt_paid_item = isnull(tamt_paid_item,0) + @var_amt_result, qtd = isnull(qtd,0) + @var_quant_result where db_contract = @var_db_contract and pc_code = @var_pc and item_no = @var_item
Hi Experts, The trigger is not sucessfully calling the Stored Procedure. This was working up until last year (12/21/2007 @ 1600 hrs.)Here I am providing codes for both Trigger and Storedprocedure.Can you help me out where the problem is?
Trigger
USE [personnelreq] GO /****** Object: Trigger [tgrTracking] Script Date: 01/16/2008 11:55:29 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO
/***************************************************************************************************************************************************************** * Trigger Name: tgrTracking * Description: Calls the CalcTrackingHours stored procedure for replacement and net staff addition * requisitions when the requisitions are emailed, transferred, or completed. * History * TKT/CO # Date Developer Description * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ * 01/03/2005 Zsofia Horompoli Created * CO#1570 03/22/2005 Zsofia Horompoli Added originator email tracking for transfer events *****************************************************************************************************************************************************************/ CREATE TRIGGER [tgrTracking] ON [dbo].[Log2] FOR INSERT AS
DECLARE @reqId int -- store requisition ID DECLARE @eventId int -- event value inserted DECLARE @parentId int -- store parent requisition ID DECLARE @eventTime datetime -- store date/time of event DECLARE @email varchar(50) -- store email address DECLARE @logId int -- store ID assigned to the record in the Log2 table DECLARE @location varchar(30) -- Location DECLARE @title varchar(30) -- Job title DECLARE @multiReq int -- > 0 = Multi NSA DECLARE @origMail varchar(50) -- Originator's email address DECLARE @subject varchar(200) -- Email subject line DECLARE @from varchar(50) -- From email DECLARE @body varchar(8000) -- Email body DECLARE @reqType int -- Requisition type (0-replacement, 1-net staff addition, 6-Bonus) DECLARE @sReqType varchar(30) -- Requisition type description DECLARE @appEmail varchar(500) -- Approvers' email addresses
SELECT @from = 'compensationandbenefits@west.com'
DECLARE @inserted_rows AS CURSOR -- hold the inserted rows SET @inserted_rows = CURSOR FOR SELECT id,reqid, timestamp, event, stuff(notes,1,patindex('%:%',notes),'') AS email FROM inserted -- get the Log2 id,requisition id, event, timestamp, and email address from the updated/inserted rows
OPEN @inserted_rows FETCH NEXT FROM @inserted_rows INTO @logId, @reqId, @eventTime, @eventId, @email WHILE (@@FETCH_STATUS = 0) BEGIN --Is this an email/transfer/complete/deny event? IF (@eventId = 4 OR @eventId = 6 OR @eventId = 7 OR @eventId = 0 OR @eventId = 10) BEGIN -- Yes, is this a deny event? IF (@eventId = 0) BEGIN --Yes, is this an active replacement/net staff addition/parent multi NSA requisition?
SELECT @parentId = id FROM reqs2 r WHERE requisitiontype in (0,1) and id = @reqId and (SELECT ParentReqId from ParentChild WHERE ChildReqId = @reqId) IS NULL and NOT (markedfortransfer = 0 AND logging <> 1) AND markedfortransfer <> 2 END ELSE IF (@eventId = 6) BEGIN SELECT @parentId = id FROM reqs2 r WHERE requisitiontype IN (0,1,6) AND id = @reqId AND (SELECT ParentReqId FROM ParentChild WHERE ChildReqId = @reqId) IS NULL and NOT (markedfortransfer = 0 AND logging <> 1) and (SELECT id FROM Log2 WHERE reqId = @reqId AND event = 0) IS NULL END ELSE IF (@eventId = 7 OR @eventId = 10) BEGIN SELECT @parentId = id FROM reqs2 r WHERE requisitiontype IN (0,1) AND id = @reqId AND (SELECT ParentReqId FROM ParentChild WHERE ChildReqId = @reqId) IS NULL and markedfortransfer <> 2 and (SELECT id FROM Log2 WHERE reqId = @reqId AND event = 0) IS NULL END ELSE BEGIN -- No, is this an active replacement/net staff addition/parent multi NSA requisition? SELECT @parentId = id FROM reqs2 r WHERE requisitiontype IN (0,1) AND id = @reqId AND (SELECT ParentReqId FROM ParentChild WHERE ChildReqId = @reqId) IS NULL and NOT (markedfortransfer = 0 AND logging <> 1) AND markedfortransfer <> 2 and (SELECT id FROM Log2 WHERE reqId = @reqId AND event = 0) IS NULL END
--Is this a requisition to be tracked? IF @parentId is not NULL BEGIN --Yes, is this a transfer event? IF @eventId = 6 BEGIN --Yes, retrieve information for email SELECT @location = RTRIM(L.DESCR), @title = RTRIM(PT.DESCR), @multiReq = (SELECT COUNT(*) FROM ParentChild WHERE ParentReqID = R.id), @reqType = R.requisitiontype FROM reqs2 R LEFT OUTER JOIN TDSdev.dbo.PS_LOCATION_TBL L ON R.sitename = L.LOCATION LEFT OUTER JOIN TDSdev.dbo.PS_JOBCODE_TBL PT ON R.jobtitle = PT.JOBCODE WHERE R.id = @reqId
-- Get email addresses to use EXEC sel_EmailUsers @reqId = @reqId, @bApprover = 1, @currentUser = NULL, @origEmail = @origMail OUTPUT, @appEmail = @appEmail OUTPUT
--Set requisition type description IF @reqType = 0 BEGIN --Replacement requisition SELECT @sReqType = 'Replacement' END ELSE IF @reqType = 1 AND @multiReq > 0 BEGIN --Multi-NSA SELECT @sReqType = 'Multiple Net Staff Addition' END ELSE IF @reqType = 1 BEGIN --NSA SELECT @sReqType = 'Net Staff Addition' END ELSE IF @reqType = 6 BEGIN --Bonus SELECT @sReqType = 'Bonus' END
--Build subject line --Do we have a location? IF @location IS NULL BEGIN --No, default to Nothing SELECT @location = '' END
--Do we have a job title? IF @title IS NULL BEGIN --No, default to Nothing SELECT @title = '' END
--Set email body IF @reqType = 6 -- If Bonus Req BEGIN SELECT @body = '<p>Bonus requisition number ' + CAST(@reqId AS varchar(15)) + ' has been processed by Compensation.</p>' SELECT @body = @body + '<p>If you have any questions, please contact us at <a href=''mailto: compensationandbenefits@west.com'' target=''_blank''>compensationandbenefits@west.com</a> .</p>' END ELSE IF @reqType IN (0,1) -- If Net Staff or Replacement Req BEGIN SELECT @body = '<p>Requisition number ' + CAST(@reqId AS varchar(15)) + ' has been finalized and sent to Human Resources on ' + convert(char(10),@eventTime, 101) + ' at ' + substring(convert(char(19),@eventTime, 100), 12, 8) + ' for recruiting.</p>' SELECT @body = @body + '<p>If you have any questions, please contact us at <a href=''mailto: compensationandbenefits@west.com'' target=''_blank''>compensationandbenefits@west.com</a> .</p>' END
-- Call the CalcTrackingHours stored procedure IF @reqType IN (0,1) BEGIN EXEC CalcTrackingHours @event = @eventId, @reqId = @reqId, @emailTo = @email, @endDateTime = @eventTime, @logId = @logId END END END FETCH NEXT FROM @inserted_rows INTO @logId, @reqId, @eventTime, @eventId, @email END
--clean up CLOSE @inserted_rows DEALLOCATE @inserted_rows
Stored Procedure is
USE [personnelreq] GO /****** Object: StoredProcedure [dbo].[CalcTrackingHours] Script Date: 01/16/2008 12:01:33 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.CalcTrackingHours Script Date: 4/12/2005 9:20:19 AM ******/
/***************************************************************************************************************************************************************** * Stored Procedure Name: CalcTrackingHours * Description: Determines the appropriate tracking level, the number of business hours the requisition * spent at the current tracking level and inserts this information into the timeLog table * History * Date Developer Description * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ * 01/03/2005 syszxh Created *****************************************************************************************************************************************************************/ CREATE procedure [dbo].[CalcTrackingHours] @event int, -- 4=Emailed,6=Transferred,7=Completed @reqId int, -- Requisition Id @emailTo varchar(50), -- Email address requisition was forwarded to @endDateTime datetime, -- Date/time of event @logId int -- ID assigned to new record in the Log2 table as set nocount on
declare @currentUserType as int -- Current user type declare @startDateTime as datetime -- Date/time requisition arrived at current step declare @newUserType as int -- New user type declare @currentTrackLevel as varchar(5) -- Tracking level to be inserted into the timeLog table declare @newTrackLevel as varchar(5) -- New tracking level declare @trackEmail as varchar(50) -- Email address at current tracking level declare @count as int -- counter variable declare @errorValue as int -- Error flag (1 = start date/time missing) declare @trackHours as decimal(10,2)
-- Retrieve last email's user type, date/time stamp, and email address select top 1 @currentUserType = userType, @startDateTime = timestamp, @trackEmail = n.userid from personnelreq.dbo.Log2 l left outer join personnelreq.dbo.names2 n on stuff(notes,1,patindex('%:%',notes),'') = n.userid where (l.event = 4 or l.event = 10) and timestamp <= @endDateTime and reqid = @reqId and l.id < @logId order by l.id desc
-- Last email found? if @startDateTime is NULL begin -- No, this is the very first email, retrieve new user type select @newUserType = userType from personnelreq.dbo.names2 n where userid = @emailTo
-- Is new user @C&B? if @newUserType = 2 begin -- Yes, set new tracking level select @newTrackLevel = 'cb1' end else begin -- No, set new tracking level select @newTrackLevel = 'dept' end end else begin -- Is this event = email? if @event = 4 begin -- Retrieve new user type select @newUserType = userType from personnelreq.dbo.names2 n where userid = @emailTo
-- Is the current user the same as the new user? if @currentUserType = @newUserType and @emailTo = @trackEmail begin -- Yes, get latest level select top 1 @newTrackLevel = trackLevel from timeLog where reqID = @reqId and trackEmail = @trackEmail and dateIn = @startDateTime order by dateIn desc
select @currentTrackLevel = @newTrackLevel end -- Is the current user type @C&B? else if @currentUserType <> 2 or @currentUserType is NULL begin -- No, retrieve current tracking level exec GetTrackLevel @userType = @currentUserType, @reqID = @reqID, @email = @trackEmail, @trackLevel = @currentTrackLevel output -- Is the new user type @C&B? if @newUserType = 2 begin -- Yes, retrieve new tracking level exec GetCBLevel @trackLevel = @currentTrackLevel, @reqID = @reqID, @currentTrackLevel = @newTrackLevel output end else -- No, retrieve new tracking level begin exec GetTrackLevel @userType = @newUserType, @reqID = @reqID, @email = @emailTo, @trackLevel = @newTrackLevel output end end else begin -- Yes, retrieve new tracking level exec GetTrackLevel @userType = @newUserType, @reqID = @reqID, @email = @emailTo, @trackLevel = @newTrackLevel output -- Retrieve current tracking level exec GetCBLevel @trackLevel = @newTrackLevel, @reqID = @reqID, @currentTrackLevel = @currentTrackLevel output end end -- Is this event = transfer/completed? else if @event = 6 or @event = 7 or @event = 10 begin -- No, any existing entries for exec3? if (select count(*) from timeLog where trackLevel = 'exec3' and reqID = @reqID) > 0 begin -- Yes, set current tracking level to cb5 select @currentTrackLevel = 'cb5' end -- Any existing entries for exec2? else if (select count(*) from timeLog where trackLevel = 'exec2' and reqID = @reqID) > 0 begin -- Yes, set current tracking level to cb4 select @currentTrackLevel = 'cb4' end -- Any existing entries for exec1? else if (select count(*) from timeLog where trackLevel = 'exec1' and reqID = @reqID) > 0 begin -- Yes, set current tracking level to cb3 select @currentTrackLevel = 'cb3' end -- Any existing entries for acct? else if (select count(*) from timeLog where trackLevel = 'acct' and reqID = @reqID) > 0 begin -- Yes, set current tracking level to cb2 select @currentTrackLevel = 'cb2' end else begin -- Set current tracking level to cb1 select @currentTrackLevel = 'cb1' end end
-- Calculate hours worked if @event <> 10 begin exec CalcBusinessHours @startDateT = @startDateTime, @endDateT = @endDateTime, @totalHours = @trackHours output
-- Update information in the timeLog table update timeLog set dateOut = @endDateTime, trackHours = @trackHours where reqID = @reqID and trackHours = 0 and dateOut = '1990-12-31' end end
-- Is this event = email? if @event = 4 and @newTrackLevel is not NULL begin -- Yes, insert new row for new track step insert into timeLog (reqID, trackLevel, dateIn, trackEmail, trackHours, dateOut) values (@reqID, @newTrackLevel, @endDateTime, @emailTo, 0, '1990-12-31') end -- Is this event = reopen? else if @event = 10 and @trackEmail is not NULL begin -- Yes, insert new row for new track step insert into timeLog (reqID, trackLevel, dateIn, trackEmail, trackHours, dateOut) values (@reqID, @currentTrackLevel, @endDateTime, @trackEmail, 0, '1990-12-31') end
hi....... i create a trigger after delete which work perfactly fine on one sqlserver2005 machine but not at another.......machine having sqlserver2005 this trigger effect 15 tables from which i am deleting data...when trigger fires..... now it cause following error when i fire ir on another machine error source: .net sql client data provider error message:maximun stored procedure,triggers,functions,or view nesting level exceeded (limit 32) plzzzz give da solution.....its really frustrating me.... thanks in advance
We've altered an UPDATE trigger - now it doesn't work properly. When updating a record (via a web application) by clearing the value for a particlar column, we get error:
UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'.
Code = 800a0c93 Source = ADODB.Recordset Description = Operation is not allowed in this context.
What the trigger does is prevent a zero-length string from being inserted into the database, which violates a check constraint, and instead inserts NULL. The web app - whose code we cannot modify - apparently does this. This was working fine, until we altered the trigger to add an additional column for update. Our SQL developer person has left, so us less knowledgable (about SQL) folks are trying to pick up the slack.
trigger code:
SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
ALTER TRIGGER trigViaNetCardholderUpdateEmptyStrings ON viewViaNetCardholder INSTEAD OF UPDATE AS UPDATE tblIDCross SET tblIDCross.chUSCId = CASE WHEN ins.chUSCId = '' THEN NULL ELSE ins.chUSCId END, tblIDCross.chNineDigit = CASE WHEN ins.chNineDigit = '' THEN NULL ELSE ins.chNineDigit END, tblIDCross.chPID = CASE WHEN ins.chPID = '' THEN NULL ELSE ins.chPID END, tblIDCross.chEmployeeId = CASE WHEN ins.chEmployeeId = '' THEN NULL ELSE ins.chEmployeeId END, tblIDCross.chAIMSNumber = CASE WHEN ins.chAIMSNumber = '' THEN NULL ELSE ins.chAIMSNumber END, tblIDCross.intCustomerType = ins.intCustomerType FROM INSERTED ins WHERE tblIDCross.intUSCardId = ins.intUSCardId
GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
I am trying to important some data in the an existing table with trigger. Unfortunately, the data were successfully inserted into the said table but the trigger did not work out. Why? How to do the tricks?
Input : 1) UPDATE TBL_SO SET QTY='10',Price='100' Where SONo='10' 2)UPDATE TBL_SO SET QTY='10',Price='100' Â Total=Qty*Price Where SONo='10'
Output: What I get? I tried both 1 and 2, It(Query) does not work on first time,I executed (Query) second time It works.Why?What I need?  How to work on First Time?
Please try the following, see that trigger is getting invoked, even if there is no row inserted into trigger table.
drop TABLE X GO CREATE TABLE X ( x1 bigint NOT NULL , x2 nvarchar(40) ) GO drop TABLE Y CREATE TABLE Y ( y1 bigint NOT NULL , y2 nvarchar(40) ) GO CREATE TRIGGER trg1 ON X FOR INSERT AS BEGIN DECLARE @prfirststatus INTEGER, @newcontextid NCHAR SELECT @newcontextid = x2, @prfirststatus = x1 FROM inserted PRINT 'See the trigger getting invoked without even a single ' + ' row being inserted in table X and values passed to this ' + ' triggers are inserted.x2 = ' + @newcontextid insert into Y values (@prfirststatus,@newcontextid) END GO insert into X SELECT y1, 'x' from Y where y2 = 'DOESNTEXIST'
We have a static class that makes an HTTPWebRequest to get XML data from one of our vendors. We use this as input to a stored proc in SQLServer2005. When I compile this class and call it from a console application in visual studio it executes in milliseconds, everytime. When I compile it, create the assembly and clr function and execute it in SQLServer, it takes around 14 seconds to execute the first time, then on subsequent requests it is again really fast, until I wait for 10 seconds and re-execute, once again it is slow the first time and then fast on subsequent requests. We do not see this behavior when executing outside SQLServer. Makes me think that some sort of authentication is perhaps taking place the first time the function is run in SQLServer? I have no idea how to debug this further. Anyone seen this before or have any ideas?
Here is the class:
Code Snippet
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO;
namespace Predict.Services { public static class Foo { public static string GetIntradayQuote(string symbol) { string returnQuote = "";
HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("http://data.predict.com/predictws/detailed_quote.html?syms=" + symbol + "&fields=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,28,30"));
StreamReader streamReader = new StreamReader(response.GetResponseStream());
returnQuote = streamReader.ReadToEnd();
streamReader.Close(); response.Close();
return returnQuote; } } }
When I run call it from a console app it is fine.
I compile it into a dll and then create the assembly and function as follows:
Code Snippet
drop function fnTestGetIntradayQuoteXML_SJS
go
drop assembly TestGetIntradayQuoteXML_SJS
go
create ASSEMBLY TestGetIntradayQuoteXML_SJS from 'c:DataBackupsCLRLibrariesTestGetIntradayQuote_SJS.dll' WITH PERMISSION_SET = EXTERNAL_ACCESS
go
CREATE FUNCTION fnTestGetIntradayQuoteXML_SJS(@SymbolList nvarchar(max)) RETURNS nvarchar(max) AS EXTERNAL NAME TestGetIntradayQuoteXML_SJS.[Predict.Services.Foo].GetIntraDayQuote
go
declare @testing nvarchar(max)
set @testing = dbo.fnTestGetIntradayQuoteXML_SJS('goog')
print @testing
When I execute the function as above, again, really slow the first time, then fast on subsequent calls. Could there be something wrong with the code, or some headers that need to be set differently to operate from the CLR in SQLServer?
I am trying to 'load' a copy of a SQLServer 2000 database to SQLServer 2005 Express (on another host). The copy was provided by someone else - it came to me as a MDF file only, no LDF file.
I have tried to Attach the database and it fails with a failure to load the LDF. Is there any way to bypass this issue without the LDF or do I have to have that?
The provider of the database says I can create a new database and just point to the MDF as the data source but I can't seem to find a way to do that? I am using SQL Server Management Studio Express.
I'm chasing after a documetn that was available on one of the Microsoftwebsites that was titled somethign like "MS SQL Server Best Practices"and detailed a nyumber of best practices about securing the server.Included in this was revoking public access to the system tableobjects.Can someone post the URL where I can pick this up, or drop me a note oncontacting them for a copy of the document?
I have an app that uses a sqlserver 2000 jdbc driver to connect to a sqlserver 2000.
Is it possible to do a direct replacement of sqlserver 2000 with sqlserver 2005 express just by reconfiguring the app to point to the express? The app would still be using the sqlserver 2000 jdbc driver to try and make the connection.
If that is a possibility, what can be some differences in the configuration? Previously with 2000 the config information I entered is:
server name: "machinename"( or ip). I've also tried "machiname/SQLEXPRESS"
DB name: name of db instance
port: 1433(default)
user and pass.
My attempts so far results in
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket."
and
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL."
I have an SQLServer Mobile database, and I would like to know if there is a way to upgrade it to SQLServer 2005 (.mdf) database. My database has no records in it, just the structure (tables etc). What I am actually asking is if I can create automatically a new SQLServer 2005 Database with the same structure as my existin SQLSErver Mobile database
I am in the process of planning a server upgrade to sql2005 x64.
I created 2 linked servers: one to a SQL2000 sp4 server and one to a SQL7.0 SP3.
I have the following error when I query the linked servers. OLE DB provider "SQLNCLI" for linked server "IVDM2K" returned message "Unspecified error". OLE DB provider "SQLNCLI" for linked server "IVDM2K" returned message "The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.". Msg 7311, Level 16, State 2, Line 1 Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server "IVDM2K". The provider supports the interface, but returns a failure code when it is used.
I am aware of KB 906954. http://support.microsoft.com/default.aspx?scid=kb;en-us;906954
I applied the instcat.sql on the SQL2000SP4 server and my linked server issues for that one are gone.
However, I ran the instcat.sql script on the SQL7.0 sp3 server and the linked server is still giving me an issue.
I had a view in which I did something like this isnull(fld,val) as 'alias'
when I assign a value to this in the client (vb 6.0) it works ok in sql2000 but fails in 2005. When I change the query to fld as 'alias' then it works ok in sql 2005 . why ?? I still have sql 2000 (8.0) compatability.
Also some queries which are pretty badly written run on sql 2000 but dont run at all in sql 2005 ???
any clues or answers ?? it is some configuration issue ?
Hi, I am new to SQL Server 2005. I tried connecting to my local machine by using my machine name as Server name and then tried running the following query: SELECT * FROM SYS.Objects. It gives me following error: Invalid object name 'sys.objects'.
Whereas, if I connect to my local machine using mahcinenameSQLEXPRESS, then the above mentioned query runs fine.
Why is this difference? What is the difference when I login in these 2 different ways. Any help would be appreciated.