Click here to Skip to main content
15,939,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please i want to select all [varchar(shortcodes)] from table to put it in dropdownlist
and make the first item in dropdownlist (All)when user select value from this list show data for this shortcode and if user select All show data for all codes

how to append word all to int data selected from table
any idea ?
Posted

You can use UNION to solve this. This is an example for interbase SQL Server. Probably you need to adapt.

SQL
SELECT  
    CAST('2' AS INTEGER),
    CAST(YOURINTFIELD AS CHAR(30))
FROM YOURTABLE
UNION
SELECT  
    CAST('1' AS INTEGER),
    CAST('All' AS CHAR(30))
FROM YOURTABLE
ORDER BY 1,2
 
Share this answer
 
Comments
eman88 6-Jun-12 15:15pm    
thanks so much it works for me :)
[no name] 6-Jun-12 15:17pm    
You are very welcome. Thank you for accepting my solution.
Regards, Bruno
VJ Reddy 6-Jun-12 19:54pm    
Good answer. 5!
[no name] 7-Jun-12 14:26pm    
Thank you. Regards.
Maciej Los 7-Jun-12 3:13am    
Good work, my 5!
You can use temporary table:

SQL
IF NOT OBJECT_ID(N'@SomeData',N'U') IS NULL
    DROP TABLE #SomeData

CREATE TABLE #SomeData(f1 INT, f2 CARCHAR(30))

INSERT INTO #SomeData (f1, f2)
SELECT f1, f2 
FROM YourTable

DECLARE @iVal INT
--get max +1 
SELECT @iVal = ISNULL(MAX(f1,0))+1 
FROM YourTable
--add 'ALL' word with corresponding value
INSERT INTO #SomeData (f1, f2)
    VALUES (@iVal, 'ALL')

--fetch data from temporary table
SELECT *
FROM #SomeData 


After all, remember to delete temporary table!
 
Share this answer
 
Comments
VJ Reddy 6-Jun-12 19:54pm    
Good alternative. 5!
Maciej Los 7-Jun-12 3:12am    
Thank you, VJ ;)

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



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