标签: sql-server-2005

ROW_NUMBER超过一个新列

是否可以通过row_number中的新列进行排序?我想做这样的事情:

select text1 + text2 as NEW_TEXT, row_number over (order by NEW_TEXT) from table
Run Code Online (Sandbox Code Playgroud)

但这样的排序不起作用(我得到随机结果).

t-sql sql-server-2005 row-number sql-order-by

1
推荐指数
1
解决办法
512
查看次数

加入不相关的表格

我在SQL Server 2005中工作.我有一个列出商店的表和一个列出部门的单独表.表之间没有关键关系.我的目标是创建一个列出每个商店的每个部门的查询.理想情况下,结果将是:

商店部门
1糖果
1冰
1饮料
2糖
2冰
2饮料

t-sql join sql-server-2005

1
推荐指数
1
解决办法
1345
查看次数

C#程序集中的SQL程序集错误

我有旧的代码,源丢失(但我们拥有它)所以我使用reflector.net解压缩它.

现在当我编译它时,我得到了这个:

 Error  1   The type 'System.ComponentModel.Component' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.  C:\NCESTableGenerator\NCESTableGenerator\db\OutputTableDAO.cs   27  20  NCESTableGenerator
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

c# asp.net assemblies sql-server-2005 compilation

1
推荐指数
1
解决办法
2530
查看次数

是否有一种解决方法允许在自己的公式中使用计算列

我的表中有一个名为Value1的列.然后我有一个计算列,Value2,公式为;

(CASE WHEN [Value1] > [Value2] THEN [Value1] ELSE [Value2] END)
Run Code Online (Sandbox Code Playgroud)

我不能保存这个,因为SQL Server在公式中的Value2计算列的自引用时很好.

还有什么我可以做的吗?

t-sql sql-server-2005 calculated-columns

1
推荐指数
1
解决办法
390
查看次数

为什么"WHERE column = NULL"在SQL Server中抛出错误?

可能重复:
在where子句+ SQL Server中IS NULL vs = NULL

考虑以下代码 - 有人可以向我解释为什么一个查询不会抛出错误?我可以理解为什么它没有返回记录,但是它想要做什么?请记住,colA是一个int.它在2000,2005和2008 r2上的工作原理相同

create table #foo
( colA int )


insert into #foo
(colA)
values
(null)

select * from #foo --returns the one record we just created

select * from #foo where colA = null --does not throw an error and does not return a record! why??
select * from #foo where colA is null --returns the record

drop table #foo
Run Code Online (Sandbox Code Playgroud)

这个表中是否存在可以返回colA = null的记录?

我目前没有任何其他数据库供我试用 - 这是标准还是特定于MSSQL的行为?

sql sql-server sql-server-2005 sql-server-2008

1
推荐指数
1
解决办法
2331
查看次数

未使用的索引会导致sql server出现性能问题吗?我应该删除它们吗?

我花了一些时间研究这个并且根本找不到明确的答案.这是我用来查找未使用的索引的查询:

SELECT object_name(i.object_id) as tableName, i.name as indexName
FROM sys.indexes i
LEFT JOIN sys.dm_db_index_usage_stats s ON i.object_id = s.object_id AND i.index_id = s.index_id AND s.database_id = db_id()
WHERE objectproperty(i.object_id,'IsUserTable') = 1 and i.index_id> 0
AND s.object_id IS NULL
AND i.is_Primary_Key = 0
AND i.is_unique_constraint = 0
AND i.is_unique = 0
Run Code Online (Sandbox Code Playgroud)

我的理解是,自上次重新启动sql server以来,查询优化器尚未使用此查询返回的索引.我相信我应该删除它们......我只是不完全了解是否存在性能影响或损害它们.

sql-server sql-server-2005

1
推荐指数
2
解决办法
1498
查看次数

为什么这个SQL Server查询会死锁?

有人能告诉我为什么以下SQL Server查询是死锁的,修复它的解决方案是什么?

<deadlock-list>
  <deadlock victim="process88b5b8">
    <process-list>
      <process id="process88b5b8" taskpriority="0" logused="76132" waitresource="RID: 32:1:151867:174" waittime="5093" ownerId="65554098" transactionguid="0xedf3314c05f1124cbe8d480cd092e03e" transactionname="DTCXact" lasttranstarted="2011-09-02T19:00:29.690" XDES="0x1029e040" lockMode="S" schedulerid="1" kpid="5108" status="suspended" spid="118" sbid="0" ecid="0" priority="0" transcount="2" lastbatchstarted="2011-09-02T19:00:31.317" lastbatchcompleted="2011-09-02T19:00:31.300" hostname="MELWFPL382S" hostpid="0" loginname="MM4" isolationlevel="repeatable read (3)" xactid="65554098" currentdb="32" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
        <executionStack>
          <frame procname="adhoc" line="1" stmtstart="78" sqlhandle="0x020000004b4b0a0d63e1040095143cbaa0174ffc3e076067"> delete from PARTIES where PARTYEXTERNALREF=@P0 and ISCOUNTERPARTY='N' and PARTYID in (select PARTYID from NAB_PARTY_EXTEND (nolock) where PARTYTYPE=@P1)     </frame>
          <frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">unknown     </frame>
        </executionStack>
        <inputbuf>(@P0 nvarchar(4000),@P1 nvarchar(4000))delete from PARTIES where PARTYEXTERNALREF=@P0 and ISCOUNTERPARTY='N' and …
Run Code Online (Sandbox Code Playgroud)

sql-server deadlock sql-server-2005

1
推荐指数
1
解决办法
1897
查看次数

插入SQL Server时希腊编码的问题

我有utf-8编码的文本文件,有超过2k行的insert命令.现在我想将它作为sql脚本执行,以将数据插入数据库.

有希腊文本有问题.插入后只有?字符,没有希腊字母.

样本插入语句如下:

INSERT INTO myDB.[MC_LIST] 
    ([id], [data], [author], [created], [language], [type_name], [position]) 
 VALUES 
    ('2086','<data><id>1</id><language>gr</language><szonelinkdest>/products/how-does-nioxin-works-page.aspx</szonelinkdest><szoneimgalt>alt</szoneimgalt><title>?????????? ????????? ??? ???????????</title><szoneimg>/m/photo/box-4.jpg</szoneimg><szonedesc>???? ?????? lala ???????? ???? ????????????? ????????? ?????????? ????????????? ??????????. </szonedesc><szonelinkname>?? ??????????? ???</szonelinkname><szonetitle>?????????? ????????? ??? ???????????</szonetitle></data>',null,'4/15/2011 3:47:47 PM','gr','1','2') ;
Run Code Online (Sandbox Code Playgroud)

怎么办才能让它发挥作用?

谢谢你的帮助.

顺便告诉您知道任何可以将utf-8文件转换为utf-16文件的软件吗?

sql-server sql-server-2005 notepad++

1
推荐指数
1
解决办法
3853
查看次数

选择从月初到当前日期的记录

我正在尝试选择在当月开始和当天之间添加到数据库的记录 - 我或多或少知道如何从当天和特定时间段内获取记录 - 但我该怎么做得到它所以它从当前日历月的开始?

select sql-server-2005 dateadd datepart

1
推荐指数
1
解决办法
6121
查看次数

用数值连接'$'

我的GridView的SelectCommand如下:

SELECT
  pubName AS Publication,
  COUNT(*) AS Total,
  SUM(CAST (price as INT)) AS Price 
FROM [SecureOrders]
WHERE DateTime >= DATEADD(day, -1, GETDATE())
GROUP BY pubName
Run Code Online (Sandbox Code Playgroud)

在我做SUM AS Price位的时候,我想在开头添加一个美元符号($),所以我的数据显示为109美元,而不是109.我试着做'$'+ SUM,当然那没用.有没有解决的办法?

gridview sql-server-2005 type-conversion

1
推荐指数
1
解决办法
2500
查看次数