sql-server-2005

How to use“ HAVING ”and “ORDER BY” clause in sql

妖精的绣舞 提交于 2019-12-24 01:41:34
问题 I have sql query like shown below the sql server says that their is error in HAVING and ORDER bY is their any error with syntax near HAVING and ORDER BY, can anyone help. SELECT Id, Name1, ZipCode, StreetName, StreetNumber, State1, Lat, Lng, Keyword, ( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) AS distance FROM Business_Details HAVING (distance < 1.5) and (Keyword like '

how to convert a single row into Column in SQL Server 2005

会有一股神秘感。 提交于 2019-12-24 01:37:22
问题 I have a table, and it is returning the data as - Column1 Column2 Column3 Column4 Column5 Column6 ------------------------------------------------------------------- 6 Joy Mycity NZ 123456 myemail@gamil.com I need to disply it as - SingleColumn ----------------------- 6 joy mycity NZ 123456 myemail@gmail.com How do I do it? 回答1: I'd make the query continue to return the data as you currently are, as individual columns, and instead make the UI code format it as it needs it. Makes it more

Issue with the big tables ( no primary key available)

我是研究僧i 提交于 2019-12-24 01:17:01
问题 Tabe1 has around 10 Lack records (1 Million) and does not contain any primary key. Retrieving the data by using SELECT command ( With a specific WHERE condition) is taking large amount of time. Can we reduce the time of retrieval by adding a primary key to the table or do we need to follow any other ways to do the same. Kindly help me. 回答1: A primary key does not have a direct affect on performance. But indirectly, it does. This is because when you add a primary key to a table, SQL Server

Adding inner query is not changing the execution plan

扶醉桌前 提交于 2019-12-24 01:14:31
问题 Consider the following queries. select * from contact where firstname like '%some%' select * from (select * from contact) as t1 where firstname like '%some%' The execution plans for both queries are same and executes at same time. But, I was expecting the second query will have a different plan and execute more slowly as it has to select all data from contact and apply filter. It looks like I was wrong. I am wondering how this is happening? Database Server : SQL server 2005 回答1: The "query

Design a process to archive data (SQL Server 2005)

点点圈 提交于 2019-12-24 00:56:55
问题 We're designing a process to archive a set of records based on different criteria like date, status, etc... Simplified set of tables: Claim, ClaimDetails, StatusHistory (tracks changes in Claim status), Comments & Files Environment: SQL Server 2005, ASP.Net MVC (.NET Framework v3.5 SP1) Claim is the main entity and it has child row(s) in the sub tables mentioned. Some have details and others are used to track changes. Eventually based on some criteria a Claim becomes "ready to archive" as

Delphi - Either BOF or EOF is True, or the current record has been deleted

半腔热情 提交于 2019-12-24 00:33:02
问题 This error showed when I tried to select on an empty table in MS SQL Server 2005: "either BOF or EOF is True, or the current record has been deleted". I have used TADOConnection and TADODataSet in Delphi 5 to connect and retrieve data from the database. Conn := TADOConnection.Create(nil); DataSet := TADODataSet.Create(nil); Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=sa;' + 'Persist Security Info=True;' + 'User ID=user;Initial Catalog=mydb;' + 'Data Source=MYPC\SQLEXPRESS;' + 'Use

Which Where condition on Datetime will be faster?

ぃ、小莉子 提交于 2019-12-24 00:19:47
问题 I have a Datetime column called CreatedOn in a table. CreatedOn is also part of a non-clustered index where the order is descending. Previously in the where condition I had a condition as follows WHERE DateDiff(d,CreatedOn,GetDate()) < 180 AND ... other conditions I changed this to WHERE CreatedOn > '2012-04-04 00:00:00.000' AND ... other conditions where I am calculating the cutoff date in C# code and then putting that in the adhoc query. According to me, the second condition should be

How can i check in MS SQL Server 2005 if a column is of a specific type

☆樱花仙子☆ 提交于 2019-12-24 00:14:28
问题 I want to change the type of a column in MS SQL Server 2005, but before i change the type of that column i want to check if that column is of the type i want to change. How can i do that in SQL? Thanxs, Bas Hendriks. Based on the anwser i wrote the following query that did the trick: IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'e_application' AND COLUMN_NAME = 'txt_locked_by' AND DATA_TYPE = 'nvarchar' AND CHARACTER_MAXIMUM_LENGTH = 15 ) BEGIN ALTER TABLE.....

@@ERROR in SQL Server 2005

喜夏-厌秋 提交于 2019-12-23 23:09:58
问题 I have learned to use the SCOPE_IDENTITY() instead of just @@IDENTITY to get the last identity value inserted in a given scope, which can be quite useful in high-concurrency scenarios. Is there any equivalent to that function for the @@ERROR variable? I mean, is there any way to make sure that whenever I write IF (@@ERROR <> 0) RETURN I am in fact forcing the function to return because of the very last command in this scope caused an error? 回答1: From Books Online: @@ERROR only returns error

How to display the exact age in Year Month Day format in SQL Server

我的未来我决定 提交于 2019-12-23 22:25:11
问题 I am stuck with my query. I have a table called Patient . In this table a column has patient DOB . Actually I want to display the exact age of the patient. For example: PatName DOB (MM/dd/yyyy) Age a 06/02/1947 65 Years 1 Month/s 3 Days b 07/10/1947 64 Years 11 Month/s 25 Days c ----------- ----------------------- I want to display the age of the above format. I have already googled about this but nobody helped. If you have any query regarding this pls post that. Thanks 回答1: Hi Check the