Click here to Skip to main content
12,546,935 members (66,832 online)
Rate this:
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 8:11am
Updated 7-Jan-13 8: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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161018.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
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