Click here to Skip to main content
11,478,896 members (64,614 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
Select CASE i.Installment_no 
            WHEN 1 THEN i.Loan_id, c.Customer_CNIC 
                   ELSE '' END AS LOAN_ID, 
            i.Installment_no, i.Date, i.Amount 
  from Installments i,
       Loan l,
       Customer c 
 where l.Loan_id = c.Loan_id 
   and c.Loan_id = i.Loan_id 
   and c.Customer_CNIC = '" + cbocnic1.Text + "-" + cbocnic2.Text + "-" + cbocnic3.Text + "' 
 order by l.Loan_id,i.Installment_no"
Posted 7-Jan-13 9:11am
Edited 7-Jan-13 9:15am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is SQL, not C#. Please tag your questions properly

I see you're building this SQL in C#, and that your SQL is built in the presentation layer, in a way that lets anyone erase or attack your DB. Read up on SQL injection attacks.

You should grab your SQL string and run it in management studio to debug it. However, the error means that it can't tell what c is, or that the column does not exist.

WHEN 1 THEN i.Loan_id, c.Customer_CNIC ELSE '' END AS LOAN_ID,

This does not work. It's probably the error. Get rid of it, you have when 1, which means you expect it to always run. I think you want

WHEN 1 THEN i.Loan_id ELSE '' END AS LOAN_ID, c.Customer_CNIC
zeshanazam at 8-Jan-13 10:54am
i want output as
Loan_id Customer_CNIC Installment_No
1234-55 12345-12222-333 1

where and what i have to change in query ?
Christian Graus at 8-Jan-13 14:06pm
Write when statements to return blank strings where you want them.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100