3

编辑:
实际上,我运行MSSQL查询,假设结果是:

身份证页名
1 1
2 01
3 01, 15

然后,我运行另一个命令 URL并将结果作为xml data,假设结果(简单形式)是:

4 01, 01 啊啊, 15
5 02
6 03
7 100
8 101
9 115

使用coldfusion,我可以将两个数据合并到一个“临时表”中。所以,实际上,我使用的是 QoQ 而不是数据库查询
END EDIT

我有一张这样的桌子

身份证页名
1 1
2 01
3 01, 15
4 01, 01 啊啊, 15
5 02
6 03
7 100
8 101
9 115

如果我想显示 pagename = 1 是否有可能结果是

身份证页名
1 1
2 01
3 01, 15
4 01, 01 啊啊, 15
4

2 回答 2

2

我认为编程代码比查询查询更幸运。我的方法类似于:

<cfset NewQuery = QueryNew("id,pagename","integer,varchar")>
<cfloop query = "ExistingQuery">
  <cfif ListFirst(pagename) EQ 1>
    code to add row and set cell values for NewQuery
  </cfif>
</cfloop>

请注意那些阅读 sql 页面的人,这是之前的评论:“@MahmoudGamal 抱歉,我正在使用 Coldfusion 函数 QueryNew 创建临时表”

换句话说,它不是数据库查询。

于 2013-07-24T12:32:06.957 回答
-1

MSSQL 的解决方案(故意健壮,parselist 函数可以帮助您将 db 标准化为更理智的东西)

帮助功能:

CREATE FUNCTION [dbo].[udf_GetNumeric]
    (@strAlphaNumeric VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
    DECLARE @intAlpha INT
    SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
    BEGIN
        WHILE @intAlpha > 0
        BEGIN
            SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
            SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
        END
    END
    RETURN ISNULL(@strAlphaNumeric,0)
END
GO

CREATE FUNCTION [dbo].[ParseList_IntAny]
(   
  @List nvarchar(1000)
)
RETURNS @Result TABLE (
  IntValue int not null
)
as
begin
  declare @Value nvarchar(20), @Position int
  select @List = LTRIM(RTRIM(@List))+ ','
  select @Position = CHARINDEX(',', @List, 1)

  if REPLACE(@List, ',', '') <> ''
  begin
    while @Position > 0
      begin
        select @Value = LTRIM(RTRIM(LEFT(@List, @Position - 1)))
        if @Value <> ''
        begin
          declare @IntValue int
          select @IntValue = dbo.udf_GetNumeric(@Value)
          insert into @Result(IntValue) values (@IntValue)
        end
        select @List = RIGHT(@List, LEN(@List) - @Position)
        select @Position = CHARINDEX(',', @List, 1)
      end
  end
  return
end
GO


declare @tmp table(ID int,  pagename nvarchar(400))
insert into @tmp
select 1,'1'
union select 2,'01'
union select 3,'01, 15'
union select 4,'01, 01 Aaa, 15'
union select 5,'02'
union select 6,'03'
union select 7,'100'
union select 8,'101'
union select 9,'115'

select * from @tmp
where exists(select top 1 1 from dbo.ParseList_IntAny(pagename) where IntValue = 1)
于 2013-07-24T08:31:54.540 回答