Click here to Skip to main content
16,017,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER procedure [dbo].[Short_Code](@Keyword varchar(10),@course varchar(10))
as
begin

declare @Batchdate varchar(20),
@AllBatchdate varchar(20),
@Coursefees varchar(50),
@Coursefees1 numeric(20),
@coursecode varchar(20),
@CHK int,
@MSG varchar(max),
@final varchar(max),
@courseelg varchar(max),
@MajorCode varchar(20)

SET @CHK=0
SET @MSG= ''
set @Batchdate = ''
set @Coursefees = '0'

SET @Keyword = UPPER(@Keyword)
select @CHK=COUNT(*),@coursecode = b.course_code from Tb_Course_Keyword as b where b.Keyword = @Keyword and b.Active <>'d' group by b.course_code

if @CHK !=0
begin
if @course = crs
begin
declare coursedate cursor for

select TOP 3 Batch_Date = convert(char(6),a.cbm_batch_start_dt,113), a.cmj_major_code from CO_BATCH_MASTER a, co_batch_number b where (b.cbn_batch_nos-(SELECT
COUNT(*) FROM BATCH_COURSE_REGISTRATION BCR,COURSE_REGISTRATION CR WHERE BCR.cr_bill_no = CR.cr_bill_no and BCR.bcr_batch_id = b.cbm_batch_id AND CR.cr_active a.cmn_minor_code= @coursecode and a.cbm_batch_id=b.cbm_batch_id and a.cbm_batch_start_dt >= getdate() and b.cbn_batch_no=1 and
<(b.cbn_batch_nos-((select><> 'D') + (isnull((select top 1 noofsheets from bulkbooking where + (isnull((select top 1 noofsheets from bulkbooking where batchid=a.cbm_batch_id and active<>'D'),0)))) order by a.cbm_batch_start_dt

set @AllBatchdate =''
open coursedate

fetch next from coursedate into @Batchdate, @MajorCode
while @@Fetch_status = 0
begin
set @AllBatchdate = @AllBatchdate + @Batchdate + ','

select top 1 @Coursefees = isnull(crm_course_rate,0) from co_rate_master where cmn_minor_code = @coursecode and crm_active <>'d'


fetch next from coursedate into @Batchdate, @MajorCode
end
close coursedate
deallocate coursedate
end
else if @course = 'elg'
begin
select distinct top 1 @courseelg = Eligibility from Eligibility where minorcode = @coursecode
set @final = 'Eligibilty for '+ @coursecode +':' + @courseelg
set @MSG = ''
goto ex;
end
else if @chk =0
begin
set @course = 'elg'
select distinct top 1 @courseelg = (select Eligibility from Eligibility where minorcode = @Keyword)

set @final = 'Eligibilty for '+ 'EFC' +' : ' + @courseelg
end
end

if @MSG = ''
begin
if @AllBatchdate = ''
begin
set @final = 'Dear Student, Thanks for contacting us'for '+ @Keyword + ' Batch dates'
end
else
begin

if @coursecode = 'DNS'
set @final = @Keyword + ' fees is Rs ' + @Coursefees + '. Visit website'
else
set @final = 'Next avaliability for ' + @Keyword + ' - ' + @AllBatchdate + ' and the fees is Rs ' + @Coursefees + '. visit website'

end
end
else
begin

set @final = 'Invalid Keyword. Sorry try again with valid keyword'
end
Ex:
select @final
end


SQL
Select * from Tb_course_keyword


SN0 Keyword courscode active
1 AFF AFF A
2 APS APS A

SQL
select * from Eligibility 

Minorcode Eligbility
EFC REO

i want to validate if Tb_course_keyword EFC Keyword is not there
and in Eligibility table EFC(minor code is there)

When i execute the store procedure i want output as follows
SQL
exec [Shor_code] 'EFC','elg'

Eligibilty for EFC : - REO

For getting a output
Eligibilty for EFC : - REO

Code as follows
SQL
if @chk =0
begin
set @course = 'elg';
select distinct top 1 @courseelg = (select Eligibility from Eligibility where minorcode = @Keyword)
set @final = 'Eligibilty for '+ 'EFC' +' : ' + @courseelg


from my above code what is the mistake i made.

But when i execute the output as follows
SQL
exec [Short_Code] 'efc','elg'

NUll

From my above store procedure what is the mistake i made?
Posted
Updated 26-Dec-14 1:38am
v2
Comments
King Fisher 26-Dec-14 4:53am    
Format your Question Properly
ZurdoDev 26-Dec-14 7:38am    
I don't follow what you're saying; however, all you have to do is debug it to find the problem.
George Jonsson 28-Dec-14 23:50pm    
Not sure if this is relevant but this line
set @final = 'Dear Student, Thanks for contacting us'for '+ @Keyword + ' Batch dates'
should be
set @final = 'Dear Student, Thanks for contacting us for ' + @Keyword + ' Batch dates'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900