9 个解决方案
#1
本人接触SQL不是太久,请高手指点,两个单引号中间一个逗号。我被弄糊涂了。执行时显示两个空字段,字段名为"无列名"
select '','' from tb
此句语法没错.
显示两个你自定义的列.
select '','' from tb
此句语法没错.
显示两个你自定义的列.
#2
如自定义A,B的值分别为1,2
select A = 1 , B = 2 from tb
select A = 1 , B = 2 from tb
#3
select '' from mytable
这个能看明白吗
再接下看
select '' as myField from myTable
能看明白吗?
看明白了继续往下看
select field1,field2 from myTable --field1,field2为myTable中字段名
继续
select field1 as myField from myTable
继续
select 'x' as myField1,'y' as myField2 from myTable
继续
select '' as myField1 , '' as myField2 from myTable
继续
select '' , '' from myTable
这个能看明白吗
再接下看
select '' as myField from myTable
能看明白吗?
看明白了继续往下看
select field1,field2 from myTable --field1,field2为myTable中字段名
继续
select field1 as myField from myTable
继续
select 'x' as myField1,'y' as myField2 from myTable
继续
select '' as myField1 , '' as myField2 from myTable
继续
select '' , '' from myTable
#4
SET QUOTED_IDENTIFIER
使 Microsoft® SQL Server™ 遵从关于引号分隔标识符和文字字符串的 SQL-92 规则。由双引号分隔的标识符可以是 Transact-SQL 保留关键字,或者可以包含 Transact-SQL 标识符语法规则通常不允许的字符。
语法
SET QUOTED_IDENTIFIER { ON | OFF }
使 Microsoft® SQL Server™ 遵从关于引号分隔标识符和文字字符串的 SQL-92 规则。由双引号分隔的标识符可以是 Transact-SQL 保留关键字,或者可以包含 Transact-SQL 标识符语法规则通常不允许的字符。
语法
SET QUOTED_IDENTIFIER { ON | OFF }
#5
A. 使用被引用的标识符设置和保留字对象名
下例显示 SET QUOTED_IDENTIFIER 设置必须为 ON,而且表名内的关键字必须在双引号内,才能创建和使用带保留关键字的对象名。
SET QUOTED_IDENTIFIER OFF
GO
-- Attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SET QUOTED_IDENTIFIER ON
GO
-- Will succeed.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SELECT "identity","order"
FROM "select"
ORDER BY "order"
GO
DROP TABLE "SELECT"
GO
SET QUOTED_IDENTIFIER OFF
下例显示 SET QUOTED_IDENTIFIER 设置必须为 ON,而且表名内的关键字必须在双引号内,才能创建和使用带保留关键字的对象名。
SET QUOTED_IDENTIFIER OFF
GO
-- Attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SET QUOTED_IDENTIFIER ON
GO
-- Will succeed.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SELECT "identity","order"
FROM "select"
ORDER BY "order"
GO
DROP TABLE "SELECT"
GO
SET QUOTED_IDENTIFIER OFF
#6
不应该理解为两个双引号 应该理解为两个'',中间没有内容的字符串字段,没有指定列名 ,选出来就是楼主描述的效果了
#7
两个字符串常量
#8
呵呵,一般写初始数值有这么做的
#9
--这样就看到比较清楚了
SELECT '' as 字段1,'' as 字段2 from tablename
#1
本人接触SQL不是太久,请高手指点,两个单引号中间一个逗号。我被弄糊涂了。执行时显示两个空字段,字段名为"无列名"
select '','' from tb
此句语法没错.
显示两个你自定义的列.
select '','' from tb
此句语法没错.
显示两个你自定义的列.
#2
如自定义A,B的值分别为1,2
select A = 1 , B = 2 from tb
select A = 1 , B = 2 from tb
#3
select '' from mytable
这个能看明白吗
再接下看
select '' as myField from myTable
能看明白吗?
看明白了继续往下看
select field1,field2 from myTable --field1,field2为myTable中字段名
继续
select field1 as myField from myTable
继续
select 'x' as myField1,'y' as myField2 from myTable
继续
select '' as myField1 , '' as myField2 from myTable
继续
select '' , '' from myTable
这个能看明白吗
再接下看
select '' as myField from myTable
能看明白吗?
看明白了继续往下看
select field1,field2 from myTable --field1,field2为myTable中字段名
继续
select field1 as myField from myTable
继续
select 'x' as myField1,'y' as myField2 from myTable
继续
select '' as myField1 , '' as myField2 from myTable
继续
select '' , '' from myTable
#4
SET QUOTED_IDENTIFIER
使 Microsoft® SQL Server™ 遵从关于引号分隔标识符和文字字符串的 SQL-92 规则。由双引号分隔的标识符可以是 Transact-SQL 保留关键字,或者可以包含 Transact-SQL 标识符语法规则通常不允许的字符。
语法
SET QUOTED_IDENTIFIER { ON | OFF }
使 Microsoft® SQL Server™ 遵从关于引号分隔标识符和文字字符串的 SQL-92 规则。由双引号分隔的标识符可以是 Transact-SQL 保留关键字,或者可以包含 Transact-SQL 标识符语法规则通常不允许的字符。
语法
SET QUOTED_IDENTIFIER { ON | OFF }
#5
A. 使用被引用的标识符设置和保留字对象名
下例显示 SET QUOTED_IDENTIFIER 设置必须为 ON,而且表名内的关键字必须在双引号内,才能创建和使用带保留关键字的对象名。
SET QUOTED_IDENTIFIER OFF
GO
-- Attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SET QUOTED_IDENTIFIER ON
GO
-- Will succeed.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SELECT "identity","order"
FROM "select"
ORDER BY "order"
GO
DROP TABLE "SELECT"
GO
SET QUOTED_IDENTIFIER OFF
下例显示 SET QUOTED_IDENTIFIER 设置必须为 ON,而且表名内的关键字必须在双引号内,才能创建和使用带保留关键字的对象名。
SET QUOTED_IDENTIFIER OFF
GO
-- Attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SET QUOTED_IDENTIFIER ON
GO
-- Will succeed.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GO
SELECT "identity","order"
FROM "select"
ORDER BY "order"
GO
DROP TABLE "SELECT"
GO
SET QUOTED_IDENTIFIER OFF
#6
不应该理解为两个双引号 应该理解为两个'',中间没有内容的字符串字段,没有指定列名 ,选出来就是楼主描述的效果了
#7
两个字符串常量
#8
呵呵,一般写初始数值有这么做的
#9
--这样就看到比较清楚了
SELECT '' as 字段1,'' as 字段2 from tablename