日期:2014-05-18  浏览次数:20536 次

SQL语句在页面中的写法???
有两个变量 small和 big 是可以从另一个表中得到的。rs.getLong("small") ....
我想 在页面中这样写个SQL语句 
select count(*) from A where ip>small and ip<big  
 
SQL可以这样写吗?

------解决方案--------------------
不可以。如果变量为整型:
'select * from a where ip>' & CStr(small) & ' and ip<' & CStr(big)
------解决方案--------------------
VBScript code

strSQL="select count(*) as cnt from A where ip>" & rs.getLong( "small") & " and   ip <" & rs.getLong( "small")

------解决方案--------------------
如果IP存的是数字. 那么可以. 会隐式转换的.
------解决方案--------------------
页面中调用需要取出2个变量的值
类似于楼上的 strSQL="select count(*) as cnt from A where ip>" & rs.getLong( "small") & " and ip <" & rs.getLong( "big") 

------解决方案--------------------
/**//*--字符型 IP 地址转换成数字 IP

--邹建 2004.08(引用请保留此信息)--*/

/**//*--调用示例

select dbo.f_IP2Int('192.168.0.11')
select dbo.f_IP2Int('12.168.0.1')
--*/
CREATE FUNCTION f_IP2Int(
@ip char(15)
)RETURNS bigint
AS
BEGIN
DECLARE @re bigint
SET @re=0
SELECT @re=@re+LEFT(@ip,CHARINDEX('.',@ip+'.')-1)*ID
,@ip=STUFF(@ip,1,CHARINDEX('.',@ip+'.'),'')
FROM(
SELECT ID=CAST(16777216 as bigint)
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1)A
RETURN(@re)
END


 GO

 SELECT * FROM a WHERE dbo.f_Int2IP(ip)>.... AND dbo.f_Int2IP<...

如果经常这么操作,建议,更改a表设置,增加ip_int列, 除了存字符型的ip外,还存int型的值, 在入库时由前台程序转换. 可以减轻服务器负担.
------解决方案--------------------
127.0.0.1 和 192.168.0.1 怎么对比啊~????