SQL中的变量引用方法

[复制链接]
查看11 | 回复4 | 2009-4-9 12:37:39 | 显示全部楼层 |阅读模式
在sql中我们经常使用语句
selet * from table1 where name = '王明'
可是这句要是放到网页制作中,'王明'换成一个变量UserName,就变成了
strSQL = "selet * from table1 where name = ' " &UserName& " '"
我不明白" &UserName& " 为什么要这么写,这一对双引号是做什么的,两个&符号是连接字符串的操作符吗,还是表示引用,请问这种引用方式是属于什么的语法asp,vbs还是sql?

回复

使用道具 举报

千问 | 2009-4-9 12:37:39 | 显示全部楼层
strSQL = "selet * from table1 where name = ' " &UserName& " '" 上面这个语句肯定是在你的asp文件中的了。asp字符串连接符是&,这个你知道的,所以,不难看出,strSQL是由三部分组成的:1. "selet * from table1 where name = ' "2. UserName3. " '"如果你把语句显示到页面上,你就可以看到,真正的语句如下(假设UserName变量的值是‘王明’):selet * from table1 where name = '王明'这也是最终你的数据库要执行的语句。这就很容易解释了,双引号在AS...
回复

使用道具 举报

千问 | 2009-4-9 12:37:39 | 显示全部楼层
1.双引号里面的表示是字符,如:strsql= "select * from table1"2.& 是连接字符串,前后都必须空格,"selet * from table1 where name =" & UserName表示是字符串加变量 Username3."selet * from table1 where name = ' " & Us...
回复

使用道具 举报

千问 | 2009-4-9 12:37:39 | 显示全部楼层
你要整句来分析,那句话是这样的:"selet * from table1 where name = ' " &UserName& " '" 即:"selet * from table1 where name = ' " //字符串& //字符串连接符UserName //字符串& //字符串连接符" '"//字符串...
回复

使用道具 举报

千问 | 2009-4-9 12:37:39 | 显示全部楼层
是asp语法的引用标识符!...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行