what i have done so far is putting @ at the starting point of the string as shown below and it is working fine:
strPreviousYearStatementQuery = @"
if exists
(select TOP 1 1 from tbl_addbill where forUser='sun4269' and bill_date is null and bill_no='2015-2016' )
begin
(select 'record found')/*table[0]*/
(select B_id,amount,amount_paid from tbl_addbill where bill_no='2015-2016' and forUser='sun4269' and bill_date is null)/*table[1]*/
(select distinct P_id from tbl_addparty where forUser='sun4269' and P_id not in (select B_id from tbl_addbill where bill_no='2015-2016' and forUser='sun4269' and bill_date is null ))/*table[2]*/
end
else begin
if EXISTS (select top 1 1 from tbl_addbill where forUser='sun4269' and bill_date between '2015-04-01' and '2016-03-31')
begin
select 'data inserted'/*table[0]*/
insert into tbl_addbill (bill_no,B_id,amount,tax,amount_paid,forUser) output inserted.B_id , inserted.amount, inserted.amount_paid /*table[1]*/
select bill_no='2015-2016', B_id, COALESCE(sum(amount),0), COALESCE (sum(tax),0), COALESCE(sum(amount_paid),0), 'sun4269' from tbl_addbill where forUser='sun4269' and bill_date between '2015-04-01' and '2016-03-31' group by B_id;
(select distinct P_id from tbl_addparty where forUser='sun4269' and P_id not in (select B_id from tbl_addbill where bill_no='2015-2016' and forUser='sun4269' and bill_date is null)/*table[2]*/)
end
else
select 'no previous year record'
end
";
but what i need to do is this and it is giving me the error :
strPreviousYearStatementQuery = @"
if exists
(select TOP 1 1 from tbl_addbill where forUser='"+userid+"' and bill_date is null and bill_no='" + (int.Parse(year.ToString()) - 1) + "-"+year+"' )
begin
(select 'record found')/*table[0]*/
(select B_id,amount,amount_paid from tbl_addbill where bill_no='" + (int.Parse(year.ToString()) - 1) + "-"+year+"' and forUser='"+userid+"' and bill_date is null)/*table[1]*/
(select distinct P_id from tbl_addparty where forUser='"+userid+"' and P_id not in (select B_id from tbl_addbill where bill_no='" + (int.Parse(year.ToString()) - 1) + "-"+year+"' and forUser='"+userid+"' and bill_date is null ))/*table[2]*/
end
else begin
if EXISTS (select top 1 1 from tbl_addbill where forUser='"+userid+"' and bill_date between '2015-04-01' and '2016-03-31')
begin
select 'data inserted'/*table[0]*/
insert into tbl_addbill (bill_no,B_id,amount,tax,amount_paid,forUser) output inserted.B_id , inserted.amount, inserted.amount_paid /*table[1]*/
select bill_no='" + (int.Parse(year.ToString()) - 1) + "-"+year+"', B_id, COALESCE(sum(amount),0), COALESCE (sum(tax),0), COALESCE(sum(amount_paid),0), '"+userid+"' from tbl_addbill where forUser='"+userid+"' and bill_date between '2015-04-01' and '2016-03-31' group by B_id;
(select distinct P_id from tbl_addparty where forUser='"+userid+"' and P_id not in (select B_id from tbl_addbill where bill_no='" + (int.Parse(year.ToString()) - 1) + "-"+year+"' and forUser='"+userid+"' and bill_date is null)/*table[2]*/)
end
else
select 'no previous year record'
end
";