sql-server-2005

Can we write a sub function or procedure inside another stored procedure

与世无争的帅哥 提交于 2019-12-20 10:25:54
问题 I want to check if SQL Server(2000/05/08) has the ability to write a nested stored procedure, what I meant is - WRITING a Sub Function/procedure inside another stored procedure. NOT calling another SP. Why I was thinking about it is- One of my SP is having a repeated lines of code and that is specific to only this SP.So if we have this nested SP feature then I can declare another sub/local procedure inside my main SP and put all the repeating lines in that. and I can call that local sp in my

SQL Insert one row or multiple rows data?

孤者浪人 提交于 2019-12-20 09:53:58
问题 I am working on a console application to insert data to a MS SQL Server 2005 database. I have a list of objects to be inserted. Here I use Employee class as example: List<Employee> employees; What I can do is to insert one object at time like this: foreach (Employee item in employees) { string sql = @"INSERT INTO Mytable (id, name, salary) values ('@id', '@name', '@salary')"; // replace @par with values cmd.CommandText = sql; // cmd is IDbCommand cmd.ExecuteNonQuery(); } Or I can build a balk

Find an object in SQL Server (cross-database)

99封情书 提交于 2019-12-20 09:49:41
问题 If I've been told a table (or proc) name, but not which connected database the object is located in, is there any simple script to search for it? Maybe search somewhere in the System Databases? (I'm using SQL Server 2005) 回答1: There is an Information_Schema schema which is a set of views on tables from the SYS schema that you can query to get what you want. The downside of the Information_Schema is that you have to write one query for each type of object. Upside is that the Information_Schema

What is the equivalent datatype of SQL Server's Numeric in C#

梦想与她 提交于 2019-12-20 09:46:25
问题 In SQL Server we can write data AS Numeric(15,10) .. what will the equivalent of this in C#? I know that Numeric 's equivalent is Decimal but how to represent Numeric(15,10) ? 回答1: There isn't a direct equivalent, in that there are no built-in .NET types which allow you to specify the precision/scale explicitly as far as I'm aware. There's no fixed -point type like NUMERIC. decimal and double are the common floating point types in .NET, with decimal implementing decimal floating point (like

SP taking 15 minutes, but the same query when executed returns results in 1-2 minutes

回眸只為那壹抹淺笑 提交于 2019-12-20 09:39:13
问题 So basically I have this relatively long stored procedure. The basic execution flow is that it SELECTS INTO some data into temp tables declared with he # sign and then runs a cursor through these tables a generate a 'running total' into a third temp table which is created using CREATE . Then this resulting temp table is joined with other tables in the DB to generated the result after some grouping etc. The problem is that this SP had been running fine until now returning results in 1-2

Semaphore Timeout Period

依然范特西╮ 提交于 2019-12-20 09:29:16
问题 I've recently wiped and reinstalled/configured all the components of my web and DB servers. I'm running IIS 6, .NET 3.5, SQL Server 2005. The two servers are separate VM's in the same domain. My web app functions perfectly... 90% of the time. But every now and then I get this error or a generic runtime error: System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has

Row_Number() with union query

社会主义新天地 提交于 2019-12-20 09:29:00
问题 I have an sql query that returns rows from two tables with same column names. I need a row number of all records in a complete result set. Following is the query select Id, VersionNumber from documents where id=5 Union all select Id, VersionNumber from versions where id=5 order by VersionNumber desc How should it be done? EDIT: And what if I only need to return a row_num where VersionNumber is lets say 5. 回答1: Try this: SELECT *, ROW_NUMBER() OVER(ORDER BY Id) ROW_NUM FROM ( select Id,

Linking ALL Users to Login after restoring a SQL Server 2005 database

流过昼夜 提交于 2019-12-20 08:07:26
问题 (Note this question asks about linking ALL Users, unlike the possible duplicate that asks about linking a single user) I wish to move a database between two servers, I have backed the database up from the first server and done a database restore on the 2nd server, so far so good. However our application makes use of a lot of database users that are defined in the database. These have to be linked to logins that are defined in the master database. The server I have restored the database to has

What is query execution doing to this query in SQL Server 2005?

丶灬走出姿态 提交于 2019-12-20 07:26:47
问题 Today I found this query in our code that pulls up a list of errors from our database: SELECT * FROM ( SELECT Substring(title, 9, Patindex('%)%', title) - 9) AS SERVICE, * FROM core.LOG WHERE logtypeid = 1 AND title LIKE 'Error: (%' AND lastmodified > '2010-06-21T00:00:00' AND lastmodified < '2010-06-22T00:00:00' ) serviceerrors WHERE SERVICE = 'CheckHelpDeskEmail' It fails with the following error: Invalid length parameter passed to the SUBSTRING function. If I remove the WHERE clause on the

writing copyfromrecordset to range

浪尽此生 提交于 2019-12-20 07:23:59
问题 I've got the following vba, it reads in the MCO from cell C10 onwards until its empty and will grab the number of machines, number of decrypts and upgrading machines from a SQL database. That works fine but I'm having trouble getting the data in the corresponding row. At the moment it always write the data to D10 coz I've hard coded it but I'm not sure how to get this to increment or write to the same row that the MCO has been read in from. I'm having the same problem if the record set is