I'm setting up a trigger that will fire off an email explaining that this entry has been updated, however I need a reference to the updated row so I only send that bit of information off.
Heres my code thus far:
ALTER TRIGGER [dbo].[completeCreation2]
ON [Database_Test].[dbo].[Projects]
AFTER UPDATE
AS
-- SEND EMAIL
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Administration',
@recipients = 'email@email.com',
@body = 'A new project has been created view details of the project below:',
@subject = 'Project Created',
@body_format = 'TEXT',
@importance = 'High',
@query = 'Select * FROM updated';
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
END
I thought the select From updated would work but it doesn't I need a reference for that line, select * FROM _____.
ID INT PK Name VARCHAR RefID FK ID Name RefID 1 Test1 <NULL> 2 Test1a 1 3 Test1b 1 4 Test1b1 3 5 Test1b1a 4
CREATE TRIGGER Update_ID ON TableA INSTEAD OF UPDATE AS IF UPDATE(ID) BEGIN DECLARE @old_ID INT DECLARE @new_ID INT
SELECT @old_ID = ID FROM DELETED SELECT @new_ID = ID FROM INSERTED
UPDATE TableA SET ID = @new_ID WHERE ID = @old_ID
UPDATE TableA SET RefID = @new_ID WHERE RefID = @old_ID END
SPROC: UPDATE TableA SET ID=6 WHERE ID=2
RefID is the FK to ID ID is also the PK to another table and has the relationship use cascading Delete and Update.
Problem: "The UPDATE statement conflicted with the SAME TABLE REFERENCE constraint" This is referring to the first UPDATE of the Trigger. It was my understanding that Instead Of checks the constraints after it is all done yet it errs with the first Trigger UPDATE. I was expecting to overcome the self-reference constraint issue by using Instead Of and with the first Trigger UPDATE, change the ID(PK) and then change the RefID(FK) with the second Trigger UPDATE. Once that was done, it should have not had any constraint problems. Thoughts?
For example, the table below, has a foreign key (ManagerId) that points to EmployeeId (primary key) of the same table. -------Employees table-------- EmployeeID . . . . . . . . . . int Name . . . . . . . . . . . nvarchar(50) ManagerID . . . . . . . . . . . int
If someone gave you an ID of a manager, and asked you to get him all employee names who directly or indirectly report to this manager. How can that be achieved?
I have a SqlDataSource - The select statement selects the DB row with an ID that equals a querystring value.... So I know I am only selecting one row..Now I want to create a little Sub that grabs any field(s) of my choice and then I can assign the value of it to a textbox on my page or a variable if I need to... Any idea how I actually reference the fields via the SQLDataSource in a sub? I see you can reference parameters using..SqlDataSource1.SelectParameters()I was hoping I could use something similar to get the actual DB fields like the below...SqlDataSource1.Select("MyDataBaseField").Value = TextBox.TextCan anyone help please??Thanks
The Background: From page 1 a search is created and this value is converted to a querystring and given the name "id=" and passed to page 2. Page 2 then does a lookup in the sql 2000 db useing this querystring. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ListingDBConnectionString %>" SelectCommand="SELECT [ID], [CompName], [Package] FROM [CDetails] WHERE ([ID] = @ID)"> <SelectParameters> <asp:QueryStringParameter Name="ID" QueryStringField="id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>
The Problem: What I then need to do is an IF THEN ELSE statement. IF [Package in SQL1] = 4 Then Package 4 IF [Package in SQL1] = 3 Then Package 3 Only how do I reference the sql value in the if statement. I have tried <%IF Eval("Package") = 4 Then %> and with Bind - No good
Hi all, How do I return pictures along with my search results? For example, I have a shoe database and for the results I would like one column to hold a picture of the shoe (the other columns hold Brand, Name, Price, etc) The way I am looking at implementing this is by referencing the image and retrieving it from the server. I'm a bit lost on how to do this though. Any help? Thanks in advance,Nick
CREATE TABLE Folder ( iD int NOT NULL IDENTITY (1, 1) PRIMARY KEY, folderName varchar(50) NOT NULL, parentFolderID int NULL FOREIGN KEY REFERENCES Folder (iD) ) GO
if I add an ON DELETE CASCADE to the foreign key, then i get an error... which is annoying. If a folder is deleted, then all its sub-folders should also be automatically deleted.
The error is: 'Introducing FOREIGN KEY constraint 'FK__Folder__parentFo__7D78A4E7' on table 'Folder' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.'
I am trying to run a mobile device with SQL's mobile 3.5. When I run my application I am given an error that sqlceme35.dll plus several other references cannot be found
When I try referencing them It does not allow me too. Is there any steps I should take to make referencing allowed?
This is probably a noob question. In reference to my previous post about OLE DB and variables, I need to copy the whole result set to a table. i tried
Code Block
exec('insert into '+@tableName+' ('+@ColumnNames+') '+@curTableResult) where @tableName is the table name, @ColumnNames are the column names and @curTableResult is the Result set produced by the Execute SQL statement before. Obviously didnt work.
A quick question. How do I reference variables (system and user) in SSIS by name instead of by just using a "?". The reason why I'm asking is because I'm trying to log what happens in a package to SQL, and if I cannot reference a variable by name it tries to insert variable values into incorrect fields?
An example of the code I'm trying to use can be found below:
Code Block UPDATE dbo.History_Control_Table SET End_Date = GetDate() , Result = 'Success' , Status = NULL , No_Of_Records_Processed = ? --This is where I want to tell it which variable to use , Package_Name = ? , No_Of_Records_Rejected = ?
--etc etc etc
WHERE Package_Name = ? AND Task_Name = 'Deals_Fact_Stg' AND Status = 'Running'
This book 'MS SQL Server 2000 Bible' says the following:
'The foreign key can reference primary keys, unique constraints, or unique indexes of any table'
I've never heard of this before, I thought that the FK always established referential integrity by referencing the PK in the parent table. Does anyone have a further explanation of this?
Is there a way to reference textboxes in an SSRS table like one would for cells in Excel? For example, something like =textbox1/textbox2? I am trying to replace a spreadsheet by turning it into an automated report and need to do some horizontal formulas and when I put in the grouped total, it always defaults to averaging percetages from the rows above, which isnt a true summary in my case.
I have a table that holds a ParentID and the RecordID. There is a column called IsEnabled which is a bit field indicating if a folder can be displayed or not. 0 = NO, 1 = YESThe table is for a directory structure which is virtual and displays folders on a web page.Root----- 1---------- 1-1---------- 1- 2----------------- 1-2-1----------------- 1-2-2----------------------- 1-2-2-1----------------- 1-2-3----------------- 1-2-4---------- 1- 3---------- 1- 4I need a query that will not select any children that are under a Parent that is disabled. So if ' 1- 2 ' is disabled then:---------- 1- 2----------------- 1-2-1----------------- 1-2-2----------------------- 1-2-2-1----------------- 1-2-3----------------- 1-2-4SHOULD NOT SHOW.Can anyone give me a query that will overcome this problem i have.-J
Anyone know a way to pull specific fields from an excel spreadsheet. I'm using SQL7 DTS to pull data into a SQL table. I can pull the entire sheet but I just want certain fields.
I have an access database and an SQL database and using data transformation services, i want to update the access database using the SQL data.
Can anyone tell me the syntax for referencing the access database?
Is it something like: [TABLENAME].dbo.FIELDNAME ?
Just to clarify, i have
Microsoft Access Database Table 1 (UnitHistory)
SQL Database Table 1 (UnitHistory)
How do i reference these seperately? I want to update the microsoft access database based on the SQL database data.
Eventually i'm trying to update an access database using the data held on my SQL server. Is DTS the best way for me to acomplish this or should i use another method?
Let say i have single dataset with different view (tables/list/matrix etc) with filter on it. Is it possible referencing from one view (table/list/matrix) to another? Basically how to access the other field for instance SUM from different view and used for the other view instead.
I have a UniqueIdentifier as a self referencing foreign key. The pk gets set by default using the newid(). I need the foreign key to default to that same value. how can i do that? @@identity doesnt work, $rowguid doesnt work, column name doesnt work. Any ideas?
select Player, sum(case when Event = 'S' then 1.0 else 0.0 end) as Success, sum(case when Event in ('S', 'F') then 1.0 else 0.0 end) as Attempts, case when Attempts > 0 then Success / Attempts else NULL end as Rating from EventList group by Player
It says comlumn names are invalid. Any idea?
Thanks, Bjoern
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Excuse me if my terminlogy is inaccurate, i'm a .NETer that's new to SQL.
I was wondering if it's possible to reference a column in the WHERE CLAUSE that has been customily defined in the SELECT statement
for example
select employeeID, case when JobCode = 'A' then 'Accountant' case when JobCode = 'C' then 'Consultant' case when JobCode = 'B' then 'Biller' End as JobType from Employee where JobType is not null
This does not work, and saids JobType is an invalid column name. Basically, what I want is to display the jobtype of the employee but i also want to only display the employees that are Accountants, consultants and billers.
Is this possible and what would be the best way of doing this?
I do not seem to be about to reference JobType in the WHERE statement.
Is there a way to refer to "current report item" using something like "this" or "me"? For example: I find myself often cutting and copying code to change the format or color of text boxes based on their value thoughout a report, and it seems like it'd be more efficient to write the formatting code once and then call it from each text box.
Excuse me if my terminlogy is inaccurate, i'm a .NETer that's new to SQL.
I was wondering if it's possible to reference a column in the WHERE CLAUSE that has been customily defined in the SELECT statement
for example
select employeeID, case when JobCode = 'A' then 'Accountant' case when JobCode = 'C' then 'Consultant' case when JobCode = 'B' then 'Biller' End as JobType from Employee where JobType is not null
This does not work, and saids JobType is an invalid column name. Basically, what I want is to display the jobtype of the employee but i also want to only display the employees that are Accountants, consultants and billers.
Is this possible and what would be the best way of doing this?
I do not seem to be about to reference JobType in the WHERE statement.
Is there a way to reference a value from a textbox in a matrix? In other words I want to pull the value in the textbox that is the column header into a cell in the matrix under certain conditions.
I have the following data set - there is more to it than whats below, I just made it easier to read and highlight my problem!
SELECT LEFT(actv.ProjID, 4) AS proj, actv.Activity, actv.TotalExpensesLB, actv.PADM FROM dbo.xtbl_MERActv actv WHERE LEFT(actv.projID,4) = @project OR actv.PADM = @PADM
What I want to do is have the user enter a 4 digit number (@project) which will correspond to LEFT(actv.ProjID, 4). The way it is now, if the user enters a 4 digit number, no records are returned. If the user enters a 6 digit number ( the real length of the projID), then it runs correctly and I get the records I want.
I have tried to use the alias 'proj' in the where statement, but I get an error message that it is an invalid column name.
Let say i have single dataset with many view (tables/list/matrix etc) and utilise "filter" to manipulate each view.
Is it possible referencing from one view (table/list/matrix) to another? Basically how to access the other field for instance SUM from different view and used for the other view instead. People mentioned about SCOPE but I don't think this is relevant to this situation ?!?!
Is there a way you can reference a prebuilt CLR function in a custom dataflow task?
The CLR and the custom dataflow task are one in the same. The reason that I'm designing the custom task is that I find that it's time consuming to make a call to the database to retrieve a function to work on something that's already in memory. Also, another reason is that if the code needs to be updated, it doesn't have to be done in 2 places allowing for less confusion.
I tried adding a reference to the CLR function in my SSIS dataflow task, but when I try running it in SSIS, I get the error saying it cannot use a SQL CLR defined task in the package which I believe is due to this reference in the CLR code:
[Microsoft.SqlServer.Server.SqlFunction] public static string toCase(string text, string caseType)
Is there a way to circumvent the [...SqlFunction] line of code when the DLL is referenced by an SSIS dataflow task, or do I just have to deal with having 2 copies of the same code?
Please see following code : SqlConnection conn=new SqlConnection(@"something....;");SqlCommand comm=new SqlCommand("Select TOP 10 * FROM TableReaderTest WITH (HOLDLOCK) ",conn); conn.Open();SqlDataReader rd;conn=null; try{ rd = comm.ExecuteReader(); rd.Close();}catch (Exception ex){ MessageBox.Show(ex.Message);} This Code works fine. I have set conn=null, still datareader is able to read the data. Why? Thank you.
In C#, when I'm using an SqlDataReader to run a simple select query and use the values returned I have a question about referencing the field values. There seem to be a large number of "Get" type methods (i.e reader.GetValue(int i), etc.) All of them (that I have found so far, require the use of the index of the field (GetValue(0) is the first field and so on). Is there a way to use the actual name of the field? (i.e. GetValue("myField"))? This helps code readability but the big reason is that changes to the underlying field list can completely hose up the application. I know there are such functions in VB, but I just can't seem to find the equivelants in C#.