将行追加到(选择语句)结果 [英] append rows to (select statement) result

查看:80
本文介绍了将行追加到(选择语句)结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我从表中选择所有[varchar(shortcodes)]并将其放入dropdownlist
当用户从此列表中选择值显示此短代码的数据,并且如果用户选择全部显示所有代码的数据",则使下拉列表中的第一项(全部)

如何将单词all附加到从表中选择的int数据
有任何想法吗?

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 ?

推荐答案

您可以使用UNION来解决此问题.这是内部数据库SQL Server的示例.可能您需要适应.

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

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


您可以使用临时表:

You can use temporary table:

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!


这篇关于将行追加到(选择语句)结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆