我想从一个字符串中的SQL删除空格,但LTRIM和RTRIM功能似乎并没有工作?
柱:
[ProductAlternateKey] [nvarchar](25) COLLATE Latin1_General_CS_AS NULL
Run Code Online (Sandbox Code Playgroud)
查询:
select REPLACE(ProductAlternateKey, ' ', '@'),
LEN(ProductAlternateKey),
LTRIM(RTRIM(ProductAlternateKey)) AS LRTrim,
LEN(LTRIM(RTRIM(ProductAlternateKey))) AS LRLen,
ASCII(RIGHT(ProductAlternateKey, 1)) AS ASCIIR,
ASCII(LEFT(ProductAlternateKey, 1)) AS ASCIIL,
ProductAlternateKey
from DimProducts
where ProductAlternateKey like '46783815%'
Run Code Online (Sandbox Code Playgroud)
结果:
| COLUMN_0 | COLUMN_1 | LRTrim | LRLen | ASCIIR | ASCIIL | PRODUCTALTERNATEKEY |
---------------------------------------------------------------------------------
| 46783815 | 8 | 46783815| 8| 53 | 52 | 46783815 |
| 46783815 | 10|46783815 | 10| 10 | 52 | 46783815 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将从SQL Server 2012中获取的备份还原到SQL Server 2008 R2,并且它会出错
指定演员表无效.(SqlManagerUI)
如果您有任何解决方案,请发表评论
谢谢.
我想使用MOD函数SQL Server 2008R2并遵循此链接 但仍然收到消息:
'MOD'不是公认的内置函数名称.
DECLARE @m INT
SET @m = MOD(321,11)
SELECT @m
Run Code Online (Sandbox Code Playgroud)
错误:
Msg 195,Level 15,State 10,Line
2'MOD'不是公认的内置函数名.
为什么我不能从上面的链接使用此功能?
我正在尝试连接到MDF.我甚至完全重新安装了sql server express(它现在是我的盒子上安装的唯一SQL的味道,之前我有05开发和快递).我已经证实路径都是正确的,到目前为止我的google-fu还没有帮助.
完整的异常消息是:
由于启动用户实例的进程失败,无法生成SQL Server的用户实例.连接将被关闭.
连接字符串是:
<add name= "CustomerEntities"
connectionString="metadata=res://*/Data.CustomerModel.csdl|res://*/Data.CustomerModel.ssdl|res://*/Data.CustomerModel.msl;
provider=System.Data.SqlClient;
provider connection string='Data Source=.\SQLEXPRESS;
AttachDbFilename=\App_Data\CustomerDb.mdf;
Integrated Security=True;
User Instance=True'"
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
我在网上发现的这个错误的几个引用不适用于我.例如,我看到的是尝试通过远程桌面启动用户实例时发生此错误的地方(我在本地执行此操作).虽然另一个人建议它与旧的快速安装中的剩余文件有关...我已经查看了指定的位置而没有找到那些文物.我也尝试过跑sp_configure 'user instances enabled', '1',但它说它已经设置为1.
user-instance sql-server-express visual-studio sql-server-2008-r2
我有一个看起来像这样的表:
AccountID, ItemID
1, 100
1, 200
2, 300
Run Code Online (Sandbox Code Playgroud)
我有一个proc接受一个表值参数,该参数更新与帐户关联的项目.我们将传递以下内容:
AccountID, ItemID
3, 100
3, 200
Run Code Online (Sandbox Code Playgroud)
proc类似于:
procedure dbo.MyProc( @Items as dbo.ItemListTVP READONLY )
AS
BEGIN
MERGE INTO myTable as target
USING @Items
on (Items.AccountId = target.AccountId)
AND (Items.ItemId = target.ItemId)
WHEN NOT MATCHED BY TARGET THEN
INSERT (AccountId, ItemId)
VALUES (Items.AccountId, Items.ItemId)
;
END
Run Code Online (Sandbox Code Playgroud)
根据传入的数据,我希望它能在表中添加2条新记录.
我想要的是有一个WHEN NOT MATCHED BY SOURCE子句,它将删除不匹配的指定帐户的项目.
例如,如果我通过
AccountID, ItemID
1, 100
1, 400
Run Code Online (Sandbox Code Playgroud)
然后我希望它删除1,200的记录; 但是留下所有其他人.
如果我这样做:
WHEN NOT MATCHED BY SOURCE THEN
DELETE; …Run Code Online (Sandbox Code Playgroud) 将存储在SQL Server表中的文件(blob)导出到硬盘驱动器上的文件的最快方法是什么?我有超过2.5 TB的文件(90 kb avg)存储为varbinary,我需要尽快将每个文件提取到本地硬盘驱动器.BCP似乎有效,但是我会看到它将花费超过45天的时间,而且我担心我的脚本会在某些时候失败,因为Management Studio会耗尽内存.
我有一个运行SSIS包的SQL服务器作业.此作业有9个步骤,每个步骤都从不同的数据库中提取数据.连接字符串在每个步骤中定义为参数.
我在运行作业时遇到以下错误.
Executed as user: USER\MYSERVER$. Microsoft (R) SQL Server Execute Package Utility Version 10.50.1600.1 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved.
Started: 5:50:55 PM Error: 2013-06-21 17:50:55.44
Code: 0xC0016016
Source:
Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available. End Error …Run Code Online (Sandbox Code Playgroud) 连接到SQL Server时出错:
Stack Trace中的详细信息如下:
===================================
Cannot connect to ServerName.
===================================
A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (.Net SqlClient Data Provider)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=233&LinkId=20476
------------------------------
Server Name: ServerName
Error Number: 233
Severity: 20
State: 0
------------------------------
Program Location:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) …Run Code Online (Sandbox Code Playgroud) 我正在使用SQL Server 2008 R2并且我有一个INT列,其中插入的数据永远不会超过最大值INT,但我有一个查询,它使用的SUM函数在执行时超过最大INT限制并抛出标题中提到的错误.
我希望能够执行此查询而不将列类型更改INT为BIGINT.
这是我的查询:
SELECT UserId,
SUM( PokemonExp ) AS TotalExp,
MAX( PokemonLevel ) AS MaxPokeLevel
FROM mytable
GROUP BY UserId
ORDER BY TotalExp DESC
Run Code Online (Sandbox Code Playgroud)
注:该PokemonExp列的类型的INT.
想要创建脚本以将数据,表和视图导出到sql脚本.
我有SQL Server 2008 r2.
到目前为止,我只能为所有表和视图自动生成sqlscript.但数据未包括在内.
或者有没有更简单的方法将数据,表,视图从一个SQL Server导出到我的ISP的SQL服务器?
问候茶