我有这个问题:
select distinct pdi.height, pdi.width, pj.jobnum
, (select count(barcode) from productiondoorinformation
inner join view_productionjobs on view_productionjobs.ctr=productiondoorinformation.productionjobsctr
where view_productionjobs.jobnum=pj.jobnum
and productiondoorinformation.height=pdi.height
and productiondoorinformation.width=pdi.width
and productiondoorinformation.alternaterating='PARTICLE') as particleqty
, (select count(barcode) from productiondoorinformation
inner join view_productionjobs on view_productionjobs.ctr=productiondoorinformation.productionjobsctr
where view_productionjobs.jobnum=pj.jobnum
and productiondoorinformation.height=pdi.height
and productiondoorinformation.width=pdi.width
and productiondoorinformation.alternaterating<>'PARTICLE') as laminatedqty
from productiondoorinformation pdi inner join view_productionjobs pj on pj.ctr=pdi.productionjobsctr
where pj.jobnum='' + @Jobnum + ''
Run Code Online (Sandbox Code Playgroud)
必须有更好的方法来成为更好的方法.我讨厌这些子选项,但是如果没有它们,我就不会吝啬重写它.当您看到每个子选项的where子句时,您会注意到子选择有两个不同的数量.
此查询需要9秒钟才能执行.那太久了.我针对这些表编写的任何其他查询都会立即返回.有什么建议?我尝试过group by等,但只能让它以某种方式工作(粒子或<>粒子),但不能同时工作.
返回的数据应如下所示:
height | width | jobnum | particleqty | laminatedqty
79 49 t1000 10 5
78 …Run Code Online (Sandbox Code Playgroud) 我在表中有一个名为CreatedOn的Datetime列.CreatedOn也是订单下降的非聚集索引的一部分.
以前在哪里条件我有如下条件
WHERE DateDiff(d,CreatedOn,GetDate()) < 180 AND ... other conditions
Run Code Online (Sandbox Code Playgroud)
我把它改成了
WHERE CreatedOn > '2012-04-04 00:00:00.000' AND ... other conditions
Run Code Online (Sandbox Code Playgroud)
我在C#代码中计算截止日期,然后将其放入adhoc查询中.
据我说,第二个条件应该更快,但我还没有看到查询执行时间的重大变化.但随着桌子大小的增加,哪一个会跑得更快?
我是SQL Server中xquery的新手.
我经常遇到使用[1]和属性的xquery表达式.
有人可以解释一下这是什么意思吗?
这是一个例子
declare @aa xml
set @aa='<data>
<row>
<Value>1</Value>
<Text>Masters</Text>
</row>
<row>
<Value>2</Value>
<Text>Transactions</Text>
</row>
<row>
<Value>3</Value>
<Text>Misch. Reports</Text>
</row>
</data>'
select a.f.value('Value[1]','varchar(50)'), -- why [1] here ?
a.f.value('Text[1]','varchar(50)') -- and here too..
from @aa.nodes('/data/row') as a(f)
Run Code Online (Sandbox Code Playgroud)
谢谢你的问候
我有一个表父和一个表子,像这样:
Parent
ID Name
1 Parent1
2 Parent2
Son
ID ParentID
10 1
20 1
30 1
15 2
25 2
Run Code Online (Sandbox Code Playgroud)
选择父母时,最简单的方法是在同一列上获得儿子的所有ID?像这样:
Result:
ID Name AllMySons
1 Parent1 10,20,30
2 Parent2 15, 25
Run Code Online (Sandbox Code Playgroud)
我想到建立一个函数来生成带有儿子的字符串,但是有人有更好的主意吗?
我有一个包含以下数据的表:
ID CAT TYPE SUBPRODUCT
--- ---- ------ ----------------
1 1 1 AA
2 1 1 BB
3 1 2 CC
Run Code Online (Sandbox Code Playgroud)
我想得到这样的数据:
CAT TYPE SUBPRODUCT
----- ------ ---------------
1 1 AA,BB
1 2 CC
Run Code Online (Sandbox Code Playgroud)
请回复我,我该怎么办.
谢谢.
我一直在尝试连接到我的localhost上的SQL Server 2005,我无法连接...
服务器名称:(本地)\ SQLEXPRESS
身份验证:Windows身份验证
我尝试过的其他服务器名称
LOCALHOST\SQLEXPRESS
(本地)\我的本地主机名
我收到此错误消息:
无法连接到127.0.0.1\SQLEXPRESS.
建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.
在服务中启用SQL Server Browser
有任何想法吗?
以下是示例查询.
CREATE PROCEDURE GetModel
(
@brandids varchar(100), -- brandid="1,2,3"
@bodystyleid varchar(100) -- bodystyleid="1,2,3"
)
AS
select * from model
where brandid in (@brandids) -- use a UDF to return table for comma delimited string
and bodystyleid in (@bodystyleid)
Run Code Online (Sandbox Code Playgroud)
我的要求是,如果@brandids或@bodystyleid为空,查询应返回该条件的所有行.
请指导我怎么做?还建议如何编写此查询以优化性能.
我遇到了一个问题,我试图在Linux服务器上恢复PHP中的MSSQL转储.我正在读取文件,然后将文件作为查询传递.
这有效:
CREATE TABLE [dbo].[recipes](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Desc] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Directions] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CompAuthor] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CompName] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Servings] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_recipes] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
Run Code Online (Sandbox Code Playgroud)
但是只要我添加像GO一样的字
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS …Run Code Online (Sandbox Code Playgroud) 我需要有关sql数据库方面的帮助。我有
表1:ENTITY_TYPE
entity_type_id entity_name
1 Task
2 Page
3 Project
4 Message
5 User
Run Code Online (Sandbox Code Playgroud)
和表2:MESSAGE,包含来自每个实体值的消息,例如
message_id entity_type owner_tableid message
1 1 12 A message on task level
2 3 14 A message on project level
Run Code Online (Sandbox Code Playgroud)
我想使用“ owner_tableid”(即查询之类)根据其所有者表中的每个实体类型和详细信息选择这些消息。
select * from MESSAGE JOIN
case entity_type when 1 then taskTable
when 2 then pageTable
when 3 then projectTable
when 4 then MessageTable
when 5 then UserTable
Run Code Online (Sandbox Code Playgroud)
在单个过程中,哪种方法是解决此问题的最佳方法。任何的想法 ??现在我为每个实体使用IF子句...
我正在使用Microsoft SQL Server我的数据库.
我的表中有一个ID列.在我的使用中,行被删除并重新创建多次.因此,如果我使用SQL Server的身份增量和身份种子,一段时间后ID号会非常大......
每个新行的ID都大于其他行并不重要.它必须是独一无二的.
如何在SQL Server中执行此操作?我应该禁用自动增量并手动设置ID吗?怎么样?
我正在使用C#和SQL Server Express.
sql-server-2005 ×10
sql ×8
sql-server ×7
t-sql ×3
c# ×1
in-clause ×1
linux ×1
localhost ×1
performance ×1
php ×1
sql-like ×1
xquery ×1
xquery-sql ×1