5
Answers

How to write sql query using checkedlistbox?

Hi,

I am going to develop the form like below screen shot. I wrote the code in itemCheck event to insert the checked item text in textbox.



My problem is: if checked items are greater than 2 I want to insert "," (comma) in between the two items.

by selecting the items from checked list box I have to write SQL query.

by removing the selection from checked list box we have to remove that item text from the query in textbox.



Can any one plz help me with code.

Thanks
Murali krishna

Answers (5)

1
Photo of Rahul Prajapat
NA 2.1k 191.7k 9y
Hello @Vilas try this query:
 
SELECT * FROM (SELECT * FROM dbo.Table_1 t UNION SELECT * FROM dbo.Table_2 t)AS Student WHERE Student.roll='E-153'
 
I hope this will help you.
Accepted
1
Photo of Karthikeyan K
NA 6.4k 488.1k 9y
SQL> CREATE TABLE SAMPLE(ID NUMBER,NAME VARCHAR(20));

Table created.

SQL> CREATE TABLE SAMPLE1(ID NUMBER,NAME VARCHAR(20));

Table created.

SQL> INSERT INTO SAMPLE(ID,NAME) VALUES('&ID','&NAME');
Enter value for id: 1
Enter value for name: KARTHIK
old 1: INSERT INTO SAMPLE(ID,NAME) VALUES('&ID','&NAME')
new 1: INSERT INTO SAMPLE(ID,NAME) VALUES('1','KARTHIK')

1 row created.

SQL> /
Enter value for id: 2
Enter value for name: MITHU
old 1: INSERT INTO SAMPLE(ID,NAME) VALUES('&ID','&NAME')
new 1: INSERT INTO SAMPLE(ID,NAME) VALUES('2','MITHU')

1 row created.
SELECT ID,NAME FROM(SELECT * FROM SAMPLE UNION ALL SELECT * FROM SAMPLE1) WHERE ID=2;
SQL> INSERT INTO SAMPLE1(ID,NAME) VALUES('&ID','&NAME');
Enter value for id: 3
Enter value for name: VINITH
old 1: INSERT INTO SAMPLE1(ID,NAME) VALUES('&ID','&NAME')
new 1: INSERT INTO SAMPLE1(ID,NAME) VALUES('3','VINITH')

1 row created.

SQL> /
Enter value for id: 4
Enter value for name: MENON
old 1: INSERT INTO SAMPLE1(ID,NAME) VALUES('&ID','&NAME')
new 1: INSERT INTO SAMPLE1(ID,NAME) VALUES('4','MENON')

1 row created.

SQL> SELECT ID,NAME FROM(SELECT * FROM SAMPLE UNION ALL SELECT * FROM SAMPLE1) WHERE ID=2;

ID NAME
---------- --------------------
2 MITHU
0
Photo of Vilas Dongre
NA 383 18.7k 9y
Actually Person is the single table through which we can find but I want single query to search single record from multiple tables
0
Photo of Rajeesh Menoth
NA 24.7k 629.6k 9y
Hi,
 
A UNION will return unique results, whereas a UNION ALL will return everything including duplicates.