sql-server

Sql Server Management Studio Object Explorer disappeared - missing - vanished

孤街浪徒 提交于 2021-02-17 21:08:25
问题 The SQL Server Management Studio Object Explorer menu disappeared. The shortcut F8 and the view->object explorer method neither do anything. I have clicked everything on the keyboard, googled around, but nothing. I really need this back, it's a massive hassle having to navigate through the summary window without the object explorer tree view! 回答1: I just had this, and the menu option... Window > Reset Window Layout ...worked a treat. 回答2: I have seen this same problem when double-clicking on

SQL Server heap v.s. clustered index

做~自己de王妃 提交于 2021-02-17 08:41:55
问题 I am using SQL Server 2008. I know if a table has no clustered index, then it is called heap, or else the storage model is called clustered index (B-Tree). I want to learn more about what exactly means heap storage, what it looks like and whether it is organized as "heap" data structure (e.g. minimal heap, maximum heap). Any recommended readings? I want to more a bit more internals, but not too deep. :-) thanks in advance, George 回答1: Heap storage has nothing to do with these heaps. Heap just

SUM OVER PARTITION BY

喜你入骨 提交于 2021-02-17 07:50:09
问题 What am I missing? This query is returning duplicate data over and over again. The count is correct for a complete total, but I am expecting one row, and yet I am getting the value repeated about 40 times. Any ideas? SELECT BrandId ,SUM(ICount) OVER (PARTITION BY BrandId ) FROM Table WHERE DateId = 20130618 I get this? BrandId ICount 2 421762 2 421762 2 421762 2 421762 2 421762 2 421762 2 421762 1 133346 1 133346 1 133346 1 133346 1 133346 1 133346 1 133346 What am I missing? I cant remove

Create a stored procedure in SQL Server that returns total count of columns in table and distinct count of values in each column

我只是一个虾纸丫 提交于 2021-02-17 07:24:16
问题 I need a stored procedure that takes any table name as a parameter and returns total count of rows and distinct count of values in each column of that particular table when executed. Let's take the sample table as below: create table journey ( Src varchar(255), Dest varchar(255) ) insert into journey values ('Jaipur', 'Mumbai'), ('Mumbai', 'Jaipur'), ('Kolkata', 'Bangalore'), ('Bangalore', 'Indore'),('Indore', 'Lucknow'), ('Lucknow', 'Indore') Can anybody help me with this task of dynamic SQL

Update PO status by SQL query

拟墨画扇 提交于 2021-02-17 07:04:10
问题 I am trying to update the PO status from 'r' to 'c' Below is the extraction query. update purchase_order set status = 'c' where STATUS = 'r' and order_date < '2019-01-01'; It was ok to update but now it appears the error message. I wonder what happened? 回答1: Assuming the example select gives all of the rows you want to change and none of the rows you don't: update purchase_order set status = 'c' where STATUS = 'r' and order_date < '2020-01-01'; You have to do this in a separate statement from

SQL Server UTC string comparison not working

烈酒焚心 提交于 2021-02-17 06:53:06
问题 we have two SQL Servers. We have the following example SQL to recreate an issue we are facing. select * from ( select '2020-11-04 08:00:00' as start union all select '2020-11-04 08:00:00' as start ) a where cast(convert(date, a.start) as datetime) + cast(Cast(a.start AS time) as datetime) > '2020-11-04 08:00:00' when we run this query of the servers, one server returns two records and the other returns zero records. Both should should return zero records. We think there is some setting that

Excel VBA: ODBC SQL server driver query timeout expired

≯℡__Kan透↙ 提交于 2021-02-17 06:30:49
问题 I have the below VBA query used in Excel 2016 that exacutes a MS Sql stored procedure, sometimes it executes smoothly and returns the recordset, but more often I get an error [Microsoft][ODBC SQL Server Driver] query timeout expired . At the same time when we go to SSMS and execute the query it runs without issues. This assumes the issue is rather caused by Excel/VB than by SQL or the query itself. Searching for this error results in checking network firewalls, but we tried on other machines

“Subquery returned more than 1 value” error

£可爱£侵袭症+ 提交于 2021-02-17 06:05:03
问题 SELECT [schoolname] AS combinationschools, CASE WHEN [schoolname] LIKE '%/%' THEN (SELECT value FROM [dbo].[Split]('/', '#6/#9E/#9M')) END AS schoolname FROM [dbo].[schools]; i'm getting q sql error like wise- Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 回答1: When you use a subquery like this, you can only have one record in the result set for each record. Clearly your table Split has

“Subquery returned more than 1 value” error

喜欢而已 提交于 2021-02-17 06:04:31
问题 SELECT [schoolname] AS combinationschools, CASE WHEN [schoolname] LIKE '%/%' THEN (SELECT value FROM [dbo].[Split]('/', '#6/#9E/#9M')) END AS schoolname FROM [dbo].[schools]; i'm getting q sql error like wise- Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 回答1: When you use a subquery like this, you can only have one record in the result set for each record. Clearly your table Split has

How to store date in dd-mon-yyyy format in SQL Server?

╄→гoц情女王★ 提交于 2021-02-17 06:00:07
问题 The below works for displaying the date, but when writing to the database [in a datetime column] it seems to be getting converted to the default format. REPLACE(CONVERT(VARCHAR(11),CONVERT(DATETIME,DATE_FIELD),106),' ','-') 回答1: Date/time values in the database are stored in a binary format. They are not stored as strings. This is the right way to store them. If you want to fetch the data in a particular format, then use the formula when you retrieve them. Or, you can add a computed column: