22

我正在将我的数据库转移到 MS SQL Server 2008 R2,当我尝试保存长字符串时,它给了我最大长度的错误,而我在替换它之后将该列的数据类型设置为“文本”使用“varchar(max)”但没有解决方案。

请为我提供如何解决此问题的解决方案。我正在执行以下查询:

update hotel 
set hotel_policy = 
    "Overview of Park Central New York - New York
    This hotel is making improvements.
        The property is undergoing renovations. The following areas are affected:
        Bar/lounge
        Business center
        Select guestrooms

    Every effort will be made to minimize noise and disturbance.
    Occupying a Beaux Arts building dating to 1927, Park Central New York Hotel is within a block of famed concert venue Carnegie Hall and within a 5-minute walk of Manhattan’s world-renowned Broadway theater district. Prefer the great outdoors to the Great White Way? Central Park is just 3 blocks from the hotel. There, you can rent a rowboat at the lake, play a game of tennis, or visit the Central Park Zoo. The international boutiques and flagship department stores of Fifth Avenue start within a 10-minute walk of the hotel. For travel to sights farther afield, there are 7 subway lines located within 3 blocks of the Park Central.
    The hotel has a snack bar for guests' convenience, and coffee and tea in the lobby.
    Retreat to your guestroom and sink into a bed with a pillowtop mattress and down comforter and pillows. Need to check email or finish up some work? You’ll find a desk with an ergonomic chair and wireless high-speed Internet access (surcharge). Unwind with a video game (surcharge) on the flat-panel HDTV."

where hotel_id = 1

我搜索了很多,但我发现的解决方案对我没有用。

谢谢!

4

3 回答 3

35

根据 ANSI SQL 标准,对对象标识符使用双引号(如有必要)(例如,UPDATE "hotel" ...)而不是作为字符串分隔符 ( "Overview of Park Central ...")。SQL Server 在QUOTED_IDENTIFIERis时具有此行为ON

编辑 1: 使用单引号和双引号作为对象标识符(包括列别名)的分隔符如下所述:

                        Delimiter   Delimiter
                        for         for
SET QUOTED_IDENTIFIER   Object ID   Alias ID        StringDelimiter
ON                      " or []     " or ' or []    '
OFF                     []          " or ' or []    " or '
  • ON然后双引号可用作对象标识符(包括列别名)的分隔符,单引号用作字符串文字和/或列别名 ( SELECT Column1 AS 'Alias1' ....) 标识符的分隔符。
  • OFF然后双引号可用作列别名 ( SELECT Column1 AS "Alias1" ...) 的分隔符和字符串文字 ( SELECT "String1" AS Alias1 ...) 的分隔符。单引号可用作字符串分隔符和列别名 ( SELECT Column1 ASAlias1 ...) 的分隔符。

改用单引号:

update hotel 
set hotel_policy = 'Overview of Park Central ...'
where hotel_id = 1
于 2013-10-26T07:45:22.763 回答
11

如果您不想将双引号更改为单引号,请在脚本的乞求中添加以下两行

 SET QUOTED_IDENTIFIER OFF
 SET ANSI_NULLS ON 
于 2014-11-10T15:43:02.143 回答
-1
 [ UPDATE denomination SET currencyType ='COINS', denomination ='1.00', currencyValue='3CAD', Active ='N', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='1.00' , UPDATE denomination SET currencyType ='COINS', denomination ='1.00', currencyValue='2CAD', Active ='N', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='1.00' , UPDATE denomination SET currencyType ='COINS', denomination ='1.00', currencyValue='2', Active ='Y', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='1.00' , UPDATE denomination SET currencyType ='NOTES', denomination ='7.00', currencyValue='8', Active ='N', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='7.00' , UPDATE denomination SET currencyType ='NOTES', denomination ='10.00', currencyValue='TENCAD', Active ='Y', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='10.00' , UPDATE denomination SET currencyType ='NOTES', denomination ='20.00', currencyValue='TWENTYCAD', Active ='N', UPDATEDBY ='EBIX_ADMIN', UPDATEDDATE =GETDATE() WHERE groupId ='EXC' AND COUNTRYCODE ='CA' AND currencyCode ='CAD' AND denomination ='20.00' ] 
于 2022-02-23T12:58:22.473 回答