Create Trigger To Format Text

Mar 4, 2015

We are using an old version of Numara TrackIT for our helpdesk software, and it doesn't have much in the way of configurable options. There is no way to set validation or formatting on the text fields in the program.

There is a field, WO_TEXT1, Which I would like to be formatted as 6 characters, 3 integers + a period + 2 integers. The first the integers would be padded with zeros on the left, and the last 2 integers would be padded with zeros on the right.

IE, if someone enters 2, it would actually end up being 002.00
If someone enters 3.5 it would end up being 003.50
If someone enters 12.1 it would end up being 012.10
If someone enters 172.80 it would end up being 172.80

I was hoping to achieve this via an update trigger.

Below is the guts of the trigger I created, mostly as a proof of concept.

-- This update properly formats the Estimated Hours field
Update t SET WO_TEXT1 = (SELECT RIGHT('000000' + CONVERT(VARCHAR(6), WO_TEXT1), 6) FROM inserted)
FROM dbo.TASKS as t
Where (EXISTS (SELECT * FROM inserted WHERE WOID = 24773));

I expected that this update trigger would only affect the Work Order with a WOID of 24773. Unfortunately, it updated all 21000 work orders in our system, wiping out all of the actual estimated hours that had been inserted by technicians!

Luckily I had a report that I could quick dump the 300 or so active work order's estimated hours back into the DB from (all the other Work orders are closed, and no one really cares about their estimated hours).

My question is three fold,

1) Why did my trigger update every record in the tasks table instead of just WO 24773?
2) Is using a trigger the best way of accomplishing what I'm trying to do?
3) if a trigger is the best way of accomplishing this, what should my trigger look like?

View 12 Replies


ADVERTISEMENT

Create Text File And Ftp With Trigger

May 24, 2007

Good day,

I hope someone can help me.

Question 1:
Is it possible to create a text file from a sql server trigger?

Question 2:
Is it possible to ftp a file from a sql server trigger?

Please if anyone can help I would appeciate it.

Thanks

View 10 Replies View Related

How To Create New CLR Trigger From Existing T-Sql Trigger

Mar 18, 2008

how to create new CLR trigger from existing T-Sql Trigger Thanks  in advance

View 3 Replies View Related

Error Msg 6522, Level 16, State 1 Receives When Call The Assembly From Store Procedure To Create A Text File And To Write Text

Jun 21, 2006

Hi,
I want to create a text file and write to text it by calling its assembly from Stored Procedure. Full Detail is given below

I write a code in class to create a text file and write text in it.
1) I creat a class in Visual Basic.Net 2005, whose code is given below:
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Diagnostics
Public Class WLog
Public Shared Sub LogToTextFile(ByVal LogName As String, ByVal newMessage As String)
Dim w As StreamWriter = File.AppendText(LogName)
LogIt(newMessage, w)
w.Close()
End Sub
Public Shared Sub LogIt(ByVal logMessage As String, ByVal wr As StreamWriter)
wr.Write(ControlChars.CrLf & "Log Entry:")
wr.WriteLine("(0) {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
wr.WriteLine(" :")
wr.WriteLine(" :{0}", logMessage)
wr.WriteLine("---------------------------")
wr.Flush()
End Sub
Public Shared Sub LotToEventLog(ByVal errorMessage As String)
Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog
log.Source = "My Application"
log.WriteEntry(errorMessage)
End Sub
End Class

2) Make & register its assembly, in SQL Server 2005.
3)Create Stored Procedure as given below:

CREATE PROCEDURE dbo.SP_LogTextFile
(
@LogName nvarchar(255), @NewMessage nvarchar(255)
)
AS EXTERNAL NAME
[asmLog].[WriteLog.WLog].[LogToTextFile]

4) When i execute this stored procedure as
Execute SP_LogTextFile 'C:Test.txt','Message1'

5) Then i got the following error
Msg 6522, Level 16, State 1, Procedure SP_LogTextFile, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'SP_LogTextFile':
System.UnauthorizedAccessException: Access to the path 'C:Test.txt' is denied.
System.UnauthorizedAccessException:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, ileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at System.IO.File.AppendText(String path)
at WriteLog.WLog.LogToTextFile(String LogName, String newMessage)

View 13 Replies View Related

I Have Sql Server Trigger In Encript Format I Want To Decript It

Jan 3, 2002

Can some some help how can i do this
PLease help me i am in problem
Thanks in Advance

View 2 Replies View Related

Is It Possible To Format (Text) In This Way

Jun 14, 2007

hi,



i want to display something is this fashion



Roth 401(k) Contribution

jfkajfkdjfdjfkdj ldkfdlkfl;dkfldkfld;fkdl



in a table row, but i am not sure how to do it. can some one pls give me some ideas.



Regards,

Karen

View 5 Replies View Related

Convert Text File Format

Mar 30, 2007

Hi,
How can I convert a text file (.txt) into SQL in ASP.net 2.0 ?  The sample of the file format is like that ...
    09/03/2007 08:41 "Fung, Kitty" Granted Access D1 Main 2354 111
    09/03/2007 08:42 "Ng, Jaclyn" Granted Access D1 Main 21906 18
    09/03/2007 08:42 "Leung, Agnes" Granted Access D1 Main 21920 18
Cheers
 

View 2 Replies View Related

Store Xml Output In Text Format

Jun 4, 2008

I have the following Query which gives the output in XML format.
select * from <Table_Name> For XML auto
I wanted to store this output in a .Xml file at my local machine.
I would prefer to have a proc when called generates the xml and stores it on the local m/c. Any ideas ?
Thanks,

View 3 Replies View Related

Dependency Tree In Text Format?

Mar 7, 2000

Hi,

I have a database of over 200 tables. I want to delete data in about 100 tables. It's hard for me to delete because there are so many dependencies. I wind up tracing each table until I find the end and then deleting backwards. Is there a script I can run where I can get a textual view of which tables are related to which tables (foreign key constraints). I don't want to hit 'display dependencies' on each table. I know I can look at logical diagram but with a database of over 200 tables, it is hard to look at it.

Thanks,
Angel

View 4 Replies View Related

Change-Format Text To Date

Jun 12, 2008

I have a column of text 010208 that is suppose to be a date. How can I changeformat this column to read 01/02/2008?

Lisa Jefferson

View 9 Replies View Related

Multi Format Text File

Apr 5, 2007

Hello. I am in the process of migrating an old app to SQL Server. The old app reads hundreds of different flat file formats. One of the more complex ones is a multi-format delimited file. For example:

01^Bob Johnson^123 Main St^Anytown^St
02^Book1^$20
02^Book2^$30
03^Gift Cert^Happy Birthday^$100

This file is delimited with the ^ character. Note that the first 2 characters identify the row type. All 01 rows have data in the format: Name, Street Address, City, State. All 02 have data in the format: Book name, price. Etc.

Any clever ideas on how to parse this? I tried setting it up as a flat file source with the ^ delimiter. It doesn't work - in this example it wraps the third row to the end of the second row and keeps adding columns to fill out the row.

The only option that I can think of is to pull the entire row into one long column, and then use a script component to manually substring each column out.

Any help would be greatly appreciated.

Thanks,
Chris

View 7 Replies View Related

Format Text Box With Parentheses If Negative

May 24, 2007

The users want to see negative values like this:



(-$1,000)



How do I format negative values that way without some major iif statement?

View 6 Replies View Related

Wired Text File Format

Jan 24, 2007

Hi,

I have a text file contains data extracted from security logs from from different servers. The format of the data looks like this

Header row

Computer,LogFile,Type,Source,EventID,EventCode,User,Date,Time,Category,CategoryString,EventType,Description


Detail row

ServerName,Security,Audit Success,Security,540,540,DomainUserName,20061231,13:36,2,Logon/Logoff,4,Successful Network Logon:

 User Name: UserName

 Domain:  Domain

 Logon ID:  (0x0,0xD4118FE)

 Logon Type: 3

 Logon Process: Kerberos

 Authentication Package: Kerberos

 Workstation Name: 

 Logon GUID: {4bcdc9b4-4caa-ce31-b202-459f1865a477}

 Caller User Name: -

 Caller Domain: -

 Caller Logon ID: -

 Caller Process ID: -

 Transited Services: -

 Source Network Address: XX.XX.XXX.XX

 Source Port: 0

If I tries to extract data as Delimited the columns are not containing the same data for each row as there are some wired characters in the "Description" filed.

How can I extract this data as proper csv file? If not is there a way to extract only ther first line in detail row as shown below

Success,Security,540,540,DomainUserName,20061231,13:36,2,Logon/Logoff,4,Successful Network Logon:

If I tries to extract as Fixed Width, it still not work. Kindly suggest, How I can achive this.

View 4 Replies View Related

How To Get Report In Text Format In SSRS?

Sep 3, 2007

Hi,

Can aybody help me in the below requirement.

I have a report like below:





<<Name Of Compnay>>
<<Name Of Report>>

<<Todays Date>>
<<ReportPeriod>> From Date - To date

The above is header and then the data in the report should come as the <<Data>> and # to be used as separator for columns.

163 #GXXX #ABC Comp Ltd. #DTDC#PPPP ABC XYZ ETC #111







*End Of Report*

How can I get this exported as it is to the .txt file?

Currently I have acheived this with SSIS, where I have kept the header template, footer template in my folder. The SSIS generates the .txt file and then I use the execute process transformation to merge the files and data. I am getting the exact o/p as I want. But in this I am intorducing lot of IO in the package by every time creating a new header for the data to be replaced as todays date and the period to be replaced by the user selected Report Period.

How can this be achived using SSRS? Is any custome code required?
Thanks in advacne for your help.


Regards,
Virendra





View 19 Replies View Related

Create New Table Format

Jan 11, 2006

Im new / novice user to writing SQL scripting. I have two tables and table1 has two columns

uslid and groupid,

uslid1, group1

uslid1, group2

uslid1, group3

uslid3, group1

uslid3, group3          etc

the second table2 has three columns

uslid, name, and location

uslid1, john, bldg 4

uslid2, jane, accounting

uslid3, joe, mail room

. I am trying to do a inner join but not working and not sure if this will work to create new temp table.  

example of what i am trying to get in new temp table on one row:

uslid, name, location, groupid1, groupid2, groupid3

uslid1, john, bldg 4, group1, group2, group3

uslid3, joe, mail room, goup1,          , group3

Hope i explained this ok. Im using 2003 server sql 2000 ver 7,  thank you in advance.

 

View 1 Replies View Related

Create Reports In ASP Format?

Sep 5, 2007

We use an internal tool that can display ASP pages. I would like to use SQL Reporting Services to create reports in ASP format. The ASP page will access the database to get data. Is this possible possible with Reporting Services?

Ric

View 2 Replies View Related

Convert Text Data To Date Format

Nov 13, 2013

I've got a field I'm trying to convert into a date format as it currently sits as a text field. The date setup is of the format DD/MM/YYYY. Some of the fields are NULL, however for the sake of filling in gaps I've just set the nulls to '01-01-1905'.

I've tried to use CAST to change the data into a readable format for SQL Server however I tend to get one of two messages:

Conversion failed when converting date and/or time from character string.

-Or-

error converting data type varchar to date

View 2 Replies View Related

Encrypt And Decrypt Text Format Data

Oct 19, 2007

Hi,

We have migrated a CRM Database from SQLServer 2000 to SQLServer 2005.



Database contains very sensitive data about customer in text format (Datatype varchar(20)) how can i encrypt the same without any change in the table design.



Regards
Sufian


View 6 Replies View Related

Create Primary Key With Increment And Format?

Nov 19, 2005

I have an access table that has a primary key (entitled "ID Number"), no duplicates, the field is an integer.And, importantly, the value is set to "increment".The format is "phd"000 -  so it starts out phd001, phd002, and so on...How to do this in an SQL table?  Can that format be done?  Or is it better not to do it via SQL but in coding instead?

View 1 Replies View Related

SQL 2012 :: How To Create XML Format File

May 21, 2015

I see this all over for creating a Format file:

bcp Northwind.dbo.Products format nul -c -f "c:Products.fmt" -T

Or this for XML

bcp AdventureWorks.HumanResources.Department format nul -c -x -f department.xml -T -S servername

I get an error saying "cannot open a connection to SQL SERVER"

The SQL Server is local on my laptop.

Here is the exact code I am using:

bcp OrderDb.CompanyDepartment foramt nul -c -x -f c:CompanyDepartment.fmt -t, -T

And I have tried :

bcp OrderDb.CompanyDepartment foramt nul -c -x -f c:CompanyDepartment.xml -t, -T

Also, some say to put the server name at the end, but then I get an unknown argument on command line error

View 1 Replies View Related

Combining Text And Value In Trigger

Nov 30, 2005

Hi,

I have written a trigger that emails a specified person.

I am trying to include a body of the email which comprises of the stock level and a warning. Pulling out my hair...Help

Code so far in the trigger is :

CREATE TRIGGER Warnings ON [dbo].[tbl_sql_cartridges_kh]
for update
AS
declare @SL as int
declare @SS as int
declare @Msg as nvarchar(100)
set @SL= (select stock_level from inserted)
set @SS =(select cartridge_key from inserted)
set @Msg = 'Print Cartridges Level Warning'
if @SL < 3
begin

exec sp_send_cdontsmail 'Print-Cartridges','XXX@XXXX.co.uk','Print Cartridges Level Warning',@Msg
end

I would like the @Msg to say something like Cartridge XXX stock level is YYY, where XXX and YYY are taken from the table after update. I can get the values, but cant put them in the MSG string..

Like @msg & @SL (SL being Stock Level)

Many Thanks

Ken

View 2 Replies View Related

Text Variable In TRIGGER

May 19, 2006

recently I wrote a TRIGGER , but I found the text is not allowed to be used.

such as:

in the trigger:

declare @content text

Is it illegal???  And why?

thank you!

View 7 Replies View Related

Create Trigger Help?

Sep 14, 2004

I have a table that has a number of data fields,I need to be able to capture datatime when the date field was entered or entered value changed.I was told I need to create a trigger on that table that contains all the fields.

I have seen the syntax for creating triggers, and read some documentation but I am still in the dark as how to create what I need to.

I was hoping to see if somebody had a similar example or an advice, anything is more than what I have at the moment.


CREATE TRIGGER NotifyDateFieldUpdates
ON RelocateeRemovalist
For INSERT, UPDATE, DELETE
AS
DECLARE @RemovalistNumber VARCHAR(200)
DECLARE @RelocateID INT

/*InspectionDate */
DECLARE getInsp CURSOR FOR SELECT RelocateID,RemovalistNumber
FROM INSERTED a LEFT JOIN DELETED b ON (a.RemovalistNumber=b.RemovalistNumber and a.RelocateID=b.RelocateID)
WHERE a.InspectionDate IS NOT NULL AND b.InspectionDate IS NULL

OPEN getInsp

FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber
WHILE (@@FETCH_STATUS <> -1)
BEGIN
INSERT INTO RelocateeRemovalistFieldEntry(RElocateID, RemovalistID)SELECT
RelocateID,RemovalistID FROM INSERTED a LEFT JOIN RelocateeRemovalistFieldEntry b ON
(a.RelocateID=b.RelocateID AND a.RemovalistNumber=b.RemovalistNumber)WHERE b.RElocateID is null


UPDATE RelocateeRemovalistFieldEntry SET InspectionDateDateTime=GETDATE()
WHERE RelocateID=@RelocateID aND RemovalistNumber=@RemovalistNumber

FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber
END

DEALLOCATE getInsp

GO

This is what I was able to come up with so far,but when i check the syntax it gives me an error "Ambiguous column name "RelocateID" and "Ambiguous column name "RemovalistNumber" I don't know what is it trying to tell me here and couldn't find much help.

Regards and thanks

View 8 Replies View Related

Create Trigger Help

May 9, 2008

i do have my 'Product' TABLE IN DATABASE 'ABC'

Product TABLE OUTPUT

PRODUCT_CODE PRODUCT_TYPE PRODUCT_DESCPRODUCT_ID PRODUCT_GROUP_CODE
6001 computer NULL ENVD14
6002 keyboard NULL ENVD14
6003 mouse NULL ENVD14
6004 cables NULL ENVD14
6005 processor NULL ENVD14

AND 'Product_Mst' TABLE IN DATABASE 'XYZ'

Product_Mst OUTPUT

PROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE
6001 0 computer NULL ENVD 14
6002 0 keyboard NULL ENVD 14
6003 0 mouse NULL ENVD 14
6004 0 cables NULL ENVD 14
6005 0 processor NULL ENVD 14

Now i want TO CREATE TRIGGER such that every updation in Product TABLE will UPDATE the appropriate record IN Product_Mst

FOR example IF i fire below query IN ABC Database

UPDATE Product
SET PRODUCT_DESC = 'Available' WHERE Product_Code = 6001

Then the OUTPUT OF the Product_Mst shoub be..

Product_Mst OUTPUT

PROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE
6001 0 computer NULL ENVD 14
6001 1 computer NULL ENVD 14
6002 0 keyboard NULL ENVD 14
6003 0 mouse NULL ENVD 14
6004 0 cables NULL ENVD 14
6005 0 processor NULL ENVD 14

Means i want to increment the version by 1 and Insert that records into Product_Mst Table at every updation.

I hope i am clear with my question.

Regards
Prashant Hirani

View 1 Replies View Related

How To Create DML Trigger

Jan 6, 2015

We have Tables like parent and Child Table.Like we have Child Table as Name AcademyContacts,In that we have Columns like

Guid(PK)Not Null,
AcademyId(FK), Not Null,
Name,Null
WorkPhone,Null
CellPhone,Null
Email Id,Null
Other.Null

Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table.if the particular columns are empty while inserting also the data will get populate into the table.And.I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID'' they cant insert the data into table.

Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.

View 4 Replies View Related

Help Me Create This Trigger

Jul 20, 2005

Hi everybody,How can I Update a field from another table by Trigger? Can someone sendme the statment to do it?I have a table called Clients with fields : ID_Clients, ClientAnd Another called Doc with fields : ID_Doc, ID_Clients, ClientThese tables are in different databases and I would like to esure theintegrity by add a Trigger to update in Docīs table the field Clienteverytime itīs changed in the Clientīs table.Thanks for Attetion.Leonardo Almeida*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

HOW TO CREATE TRIGGER ?

Jul 20, 2005

Hii have 2 Tablefirst one : Customerwith 4 Fields : cst_no,cst_name,total_Debit,tot_creditsecond one : Transactionwith 5 Fields : Trns_no,Trns_Date,cst_no,debit,creditMY QUESTION:HOW TO CREATE TRIGGER FOR UPDATE TOT_DEBIT AND TOT_CREDIT FILEDS INCUSTOMER TABLE FROM Transaction TABLEThank you

View 4 Replies View Related

Create A Trigger Through C#/.NET

Jan 10, 2008

Hi folks,

I have created a trigger that I can enter and works great from the sqlcmd terminal. When I try to submit the same query in a .NET project I get an error that "Create Trigger must be the first statement in a batch". The Create trigger is submitted by itself through the sqlcommand.executenonquery() method.

I am trying to create a database for a project but the only thing that I can't seem to get working is submitting this trigger.

Appreciate any help.

Dave

View 5 Replies View Related

Help To Create Trigger

May 10, 2008

I am trying to create a trigger to help me get a the time duration but this is not working.






Code Snippet

CREATE TRIGGER Duratn

ON dbo.CONTACTS
AFTER INSERT, UPDATE, DELETE
AS
SET NOCOUNT ON
UPDATE dbo.CONTACTS
SET Duratn = (DATEDIFF(CallStartTime) - DATEDIFF(CallFinishTime))



My table is as follows:

No Caller CallStartTime CallFinishTime Duratn

10000 John 10/05/2008 18:13:00 10/05/2008 18:14:00 NULL

View 13 Replies View Related

Trigger. How To Create?

Oct 4, 2007

What I was trying to use to create the trigger was the same code I would use on Sql Server Express:

cmd.CommandText = "CREATE Trigger [contactsLastUpdate] on [contacts] for Insert, Update " +
"AS " +
"Begin " +
"SET NOCOUNT ON " +
"Update t " +
"set syncLastUpdate = GetDate() " +
"From contacts t " +
"Join inserted i " +
"On t.id = i.id " +
"SET NOCOUNT OFF " +
"End"; +

But I get an error message:

"There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = Trigger ]"

How do you guys create Triggers on SQL Server CE (2005)?

Thanks

View 3 Replies View Related

Query String Field Based On Text Format

Mar 7, 2008

I need to search a nvarchar field based on the format of the text.  This field holds values in two formats: 000 000 000 000 and 000000.   I only want to search through the records that are in the 000 000 000 000 format.  Can anyone give me direction on how to go about doing this or give me some key words to search for on Google?  Fixing this problem is not an option.  This is a county tax DB from a poor county with almost a million records in it. 
 Thanks for the help!

View 2 Replies View Related

Keeping Text Format After Stored In The Data Base.

Jan 14, 2004

I want the users of my site to be able to write a couple of paragraphs, save it to SQL Server and then have it read back and look the same. I don't want the users to be able to add any html to the text they submit. I just want them to be able to seperate or indent their paragraphs.

At one point, I had a textbox that saved text to the server and read it back the same way it was originally inputed. However, I can't figure our what I had done to make it work.

Any ideas?
Thanks

View 2 Replies View Related

SQL 2012 :: Date Format In Text Column With Many Other Inputs

Feb 10, 2014

How to convert MM/YYYY to MM/DD/YYYY and also YYYY to 01/01/YYYY.

This column is text column and has many other inputs.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved