User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 397,706 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,359 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:

Trigger help

Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Trigger help

  #2  
Apr 3rd, 2007
I don't think a trigger is what you want here, consider a user-defined function instead:

create function getNote (@score int) 
returns nvarchar(4) 
as
begin
	declare @note nvarchar(4)

	if @score between 0 and 50 
		set @note = 'Half'
	else
		set @note = 'Full'

	return @note
end

and the test case to show how it works
--Test case
create table #exam 
(
	e_id int identity(1,1) primary key,
	e_score int,
	e_note nvarchar(4)
)

insert into #exam(e_score, e_note) 
values (51, dbo.getNote(51)) 

insert into #exam(e_score, e_note) 
values (50, dbo.getNote(50)) 

select * from #exam

drop table #exam

RESULTS:
========
e_id        e_score     e_note 
----------- ----------- ------ 
1           51          Full
2           50          Half
Last edited by hollystyles : Apr 3rd, 2007 at 7:46 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
All times are GMT -4. The time now is 1:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC