sql-server-2005

Function call in where clause

我的未来我决定 提交于 2019-12-12 10:38:14
问题 I have a query as below: SELECT * FROM Members (NOLOCK) WHERE Phone= dbo.FormatPhone(@Phone) Now here I understand that formatting has to be applied on the variable on column. But should I apply it on variable to assign to some other local variable then use it (as below). Set @SomeVar = dbo.FormatPhone(@Phone) SELECT * FROM Members (NOLOCK) WHERE Phone= @SomeVar Which way is better or both are good? EDIT: And how is first query different from SELECT * FROM Members (NOLOCK) WHERE dbo

INSERT permission was denied on the object 'employee_info', database 'payroll' schema dbo

一世执手 提交于 2019-12-12 10:34:58
问题 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconnection As SqlConnection Dim mycommand As SqlCommand Dim ra As Integer myconnection = New SqlConnection("server=IAI-004;uid=;pwd=;database=payroll") myconnection.Open() mycommand = New SqlCommand("INSERT INTO employee_info([employee_id],[first_name],[last_name],[middle_name],[email],[telephone],[gender],[status],[date_birth],[hire_date]) values ('" & Employee_idTextBox.Text & "

SQL query like GROUP BY with OR condition

﹥>﹥吖頭↗ 提交于 2019-12-12 10:33:49
问题 I'll try to describe the real situation. In our company we have a reservation system with a table, let's call it Customers , where e-mail and phone contacts are saved with each incoming order - that's the part of a system I can't change. I'm facing the problem how to get count of unique customers. With the unique customer I mean group of people who has either the same e-mail or same phone number. Example 1 : From the real life you can imagine Tom and Sandra who are married. Tom, who ordered 4

Find unique values in a column of comma separated text

不想你离开。 提交于 2019-12-12 10:11:25
问题 I have a column "A" that are separated by commas and I want to find all the unique values in Column A. Here's a very short example: Column A 111, 222 333 444 777,999 I want a query which gives me the following value: Column C 111 222 333 444 777 999 回答1: Ignoring the obvious problems with your table design as alluded to in all the comments and accepting that this might prove very slow on a huge table here's how I might do it. First... I would create a statement that would turn all the rows

Consolidate data from many different databases into one with minimum latency

烈酒焚心 提交于 2019-12-12 09:53:38
问题 I have 12 databases totaling roughly 1.0TB, each on a different physical server running SQL 2005 Enterprise - all with the same exact schema. I need to offload this data into a separate single database so that we can use for other purposes (reporting, web services, ect) with a maximum of 1 hour latency. It should also be noted that these servers are all in the same rack, connected by gigabit connections and that the inserts to the databases are minimal (Avg. 2500 records/hour). The current

connect sql server 2005/2008 over internet

大憨熊 提交于 2019-12-12 09:53:32
问题 How do I connect to SQL Server 2005/2008 using Management Studio or other desktop application over the internet? 回答1: Check out WCF Data Services : http://msdn.microsoft.com/en-us/data/bb931106.aspx That way, you don't have to totally expose your database server out to the internet, but you get fine grained control over what gets exposed and who (which type of user) can see or modify what. Marc 回答2: I finally solved this by: Changing default SQL Port to 8080 from 1433 (our ISP was blocking)

Suitable indexes for sorting in ranking functions

时光怂恿深爱的人放手 提交于 2019-12-12 09:45:20
问题 I have a table which keeps parent-child-relations between items. Those can be changed over time, and it is necessary to keep a complete history so that I can query how the relations were at any time. The table is something like this (I removed some columns and the primary key etc. to reduce noise): CREATE TABLE [tblRelation]( [dtCreated] [datetime] NOT NULL, [uidNode] [uniqueidentifier] NOT NULL, [uidParentNode] [uniqueidentifier] NOT NULL ) My query to get the relations at a specific time is

SQL Server Query Performance - Clustered Index Seek

冷暖自知 提交于 2019-12-12 09:45:17
问题 Excuse the long post, but below I have included a full script to generate and populate my test harness. My test harness has the following tables |--------| |-------------| |-----| |--------------| |Column | |ColumnValue | |Row | |RowColumnValue| |--------| |-------------| |-----| |--------------| |ColumnId| |ColumnValueId| |RowId| |RowId | |Name | |ColumnId | |Name | |ColumnValueId | |--------| |Value | |-----| |--------------| |-------------| They represent Rows and Columns in a table. The

Storing a c# DateTimeOffset value in a SQL Server 2005 database

橙三吉。 提交于 2019-12-12 09:39:07
问题 I want to store a a c# DateTimeOffset value in a SQL Server 2005 database. Sql 2008 has this as a built-in-type, but SQL Server 2005 does not. The DateTimeOffset structure has a DateTime value wich I store as DateTime, an an Offset property (of type TimeSpan). Since this is the time zone relative to UTC, presumably it is usally at a whole number of hours or half-hours. Suggestions on how best to store this in a SQL Server 2005 database? 回答1: It's not a good idea to assume that an offset is a

Parameter doesn't perform as well as hard coding the value

为君一笑 提交于 2019-12-12 09:37:53
问题 I have a stored procedure that performs terribly. When I declare a variable, set its value and then use it in the where clause the statement takes over an hour to run. When I hard code the variables in the where clause it runs in less than a second. I started to look into what was wrong with it through execution plans. It looks like when I try and pass it some declared variables the execution plan crates some Hash Match because it selects values from a view that uses a UNION and a common