SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 row count
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

oracle_corrgi
Yak Posting Veteran

India
98 Posts

Posted - 09/04/2006 :  03:06:06  Show Profile  Reply with Quote
hi

i think i have confused u all or unable to explain prorperly


see i want to write case function
if the output record is >1 can case 1
else case two

say i have more then one record output or zero
if it is zero case2
else case 1

sample code

-----SELECT ed.tpa_id,
ed.division_key,
emd.tpa_id,
emd.empe_key
from dbo.EMPLOYER_DIVISION AS ED,EMPLOYEE_MISC_DATA AS EMD

DECLARE
@rc tinyint ,
@var varchar(50)
set @var = (SELECT emd.tpa_id
from dbo.EMPLOYER_DIVISION AS ED,EMPLOYEE_MISC_DATA AS EMD
where emd.tpa_id=ed.tpa_id
and
emd.empe_key=ed.division_key)



Edited by - oracle_corrgi on 09/04/2006 06:13:47

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 09/04/2006 :  03:09:37  Show Profile  Reply with Quote
don't quite understand your requirement. Can you post some sample table & data ?


KH

Go to Top of Page

chiragkhabaria
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/04/2006 :  03:09:57  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
using Having Query


Chirag
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 09/04/2006 :  03:38:48  Show Profile  Visit SwePeso's Homepage  Reply with Quote
I think he means something like this
SELECT		ed.tpa_id,
		ed.division_key,
		emd.tpa_id,
		emd.empe_key,
		ISNULL(rctpa_id, ed.tpa_id)
from		dbo.EMPLOYER_DIVISION AS ED,
LEFT join	EMPLOYEE_MISC_DATA AS EMD ON emd.tpa_id = ed.tpa_id and emd.empe_key = ed.division_key


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 09/04/2006 :  05:28:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Oh, now you have to questions in the same topic. For the first question (the original)
SELECT		ed.tpa_id,
		ed.division_key,
		emd.tpa_id,
		emd.empe_key,
		case
			when @rc = 1 then RCONE
			when @rc > 2 then RCTWO
			ELSE NULL
		END
from		dbo.EMPLOYER_DIVISION AS ED
inner join	EMPLOYEE_MISC_DATA AS EMD on emd.tpa_id=ed.tpa_id and emd.empe_key=ed.division_key
order by	5


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 09/04/2006 :  05:31:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Second question is harder to tell when we know nothing about @divstr looks
CREATE procedure GetDivisionKeyAssigEmployee
(
	@empid varchar(20),
	@tpid varchar(20),
	@divstr varchar(20),
	@rs tinyint OUTPUT
)
as

SET NOCOUNT ON

declare	@ekey char(2),
	@divs2 varchar(10)

select @ekey = empe_key
from	vw_employee
where	tpa_id = @tpid
	and empr_id = @empid

select	@divs2 = division_key
from	vw_employee_misc_data
where	tpa_id = @tpid
	and empe_key = @ekey

if @divs2 = substring(@divstr, 1, charindex(',', @divstr, 1) - 1)
	select @rs = 1
else
	if @divs2 = substring(@divstr, charindex(',', @divstr, 1) + 1, 2)
		select @rs = 1
	else
		if @divs2 = substring(@divstr, charindex(',', @divstr, charindex(',', @divstr, 1) + 1), 2)
			select @rs = 1
		else
			select @rs = 0


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 09/04/2006 :  06:21:27  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Don't change the original posting. Now we have no idea what you are trying to achieve.
What is CASE 1 and what is CASE 2?
What is output record?



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chiragkhabaria
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/04/2006 :  11:12:40  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
quote:
Originally posted by Peso

Don't change the original posting. Now we have no idea what you are trying to achieve.
What is CASE 1 and what is CASE 2?
What is output record?



Peter Larsson
Helsingborg, Sweden



Aha.. i guess its better to put quotes and then reply so it helpful to others for the future reference.. also..

Chirag
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000