sql-server-2005

There is already an object named '#result' in the database

与世无争的帅哥 提交于 2019-12-21 20:36:09
问题 Alter Procedure sp_Member( @comcode int = 0, @SubComCode int = 0 ) as begin set nocount on If @comcode='0' begin select ( select sum(amount) from tbcoudet where memcode=tbm.memcode and expyear=(select max(expyear) from tbexpyear) and exists ( select itemcode from tbitem where comcode=@comcode and SubComCode=@SubComCode and itemcode=tbcoudet.itemcode ) group by memcode,expyear )'TurnOver', * into #result from tbmember tbm where can_flag='N' end If @subcomcode='0' begin select ( select sum

SQL Server Globally Unique Identifiers

风格不统一 提交于 2019-12-21 20:33:29
问题 When or why will one need to use Globally Unique Identifiers instead of the traditional Idenity column? Please help me understand 回答1: One reason is replication and scalability : When multiple, uncoordinated writers exist, they -- by definition -- have no channel to communicate for creating unique int s for the primary key. GUIDs don't need communication to be unique. 回答2: In addition to the replication elements mentioned by other answers... When you need to create unique values but do not

How to create SQL Server table schema from a XML schema? (with .NET and Visual Studio 2008)

[亡魂溺海] 提交于 2019-12-21 20:30:30
问题 I have a XML schema, and I know that "xsd.exe" can generate the C# code for it. But I want to know if is possible to automatically create the MS SQL Server 2005+ tables from the XSD, with the help of this or other tools. BTW I didn't get what the C# code generated by "xsd.exe" is worth for. What's the difference between code generated by CodeXS and xsd.exe? 回答1: You can use the XSD2DB utility This is the Example xsd2db.exe -f true -l [Server Name] -n [Database Name] -s D:\po.xsd -t sql Link

SQL Server row lock

风格不统一 提交于 2019-12-21 20:29:29
问题 How to row lock in SQL Server 2005. I execute a sql for row locking and that is SELECT * FROM authors WITH (HOLDLOCK, ROWLOCK) WHERE au_id = '274-80-9391' it work fine but in this case row is lock for update not for selection. I just want to know how to lock a row as a result another user can not see that row when issue a SQL in SQL Server. please guide me. thanks 回答1: You can't hide a row so that it won't be seen by other SQL queries. If you open a transaction, lock a row, and hold open the

Send email for each row in a result set

谁都会走 提交于 2019-12-21 20:28:07
问题 I'd like to send an email for each row of a result set using sp_send_dbmail. What is the appropriate way to accomplish this without using loops? Edit: I'm not insisting a loop is not proper here, but is there a set based way to do this. I've tried creating a function, but a function cannot call a stored proc inside it. Only another func or extended sp (which I'd rather not do either). 回答1: The best way to accomplish this is to put your email sending logic in a user defined function. Then you

Calculate the maximum storage size of table record?

不问归期 提交于 2019-12-21 20:25:28
问题 Is there a way to determine what the maximum size of a record would be in SQL Server past doing it by hand? For example: CREATE TABLE test ( id INT PRIMARY KEY IDENTITY(1, 1), name VARCHAR(256), test_date DATETIME ) so, if I'm not mistaken, when calculating that by hand that record could be a maximum of 272 bytes . However, I have a table with a lot more columns than that, and I need to do this for more than one table, so I wanted to know if I could do this with a simple query. I can't find

PHP trying to login to MSSQL (windows authentication) with computer name instead of login name

时间秒杀一切 提交于 2019-12-21 20:25:03
问题 I am trying to establish a connection to my company's MSSQL server with windows authentication , but it fails as it is trying to use my computer name as login instead of my login id. When logging in with the MS SQL Server Management the windows authentication works fine, but not with this PHP code: <?php // Server in the this format: <computer>\<instance name> or // <server>,<port> when using a non default port number $serverName = "xxx"; $connectionInfo = array( "Database"=>"xxx"); /*

Default parameter values/optional parameters for .NET stored procedures in SQL Server 2005

时间秒杀一切 提交于 2019-12-21 20:22:37
问题 SQL Server a stored procedure written in C# on the .NET 2.0 framework that has a SqlInt32 parameter. I am trying to make the parameter optional. Here is a minimal test case that just prints the integer passed to it: [Microsoft.SqlServer.Server.SqlProcedure] public static void TestProc( SqlInt32 TestInt ) { SqlPipe pipe; pipe = SqlContext.Pipe; if (TestInt.IsNull) { pipe.Send("NULL value passed"); } else { pipe.Send(TestInt.ToString()); } } These commands execute as expected, and print "1" and

Default parameter values/optional parameters for .NET stored procedures in SQL Server 2005

三世轮回 提交于 2019-12-21 20:20:13
问题 SQL Server a stored procedure written in C# on the .NET 2.0 framework that has a SqlInt32 parameter. I am trying to make the parameter optional. Here is a minimal test case that just prints the integer passed to it: [Microsoft.SqlServer.Server.SqlProcedure] public static void TestProc( SqlInt32 TestInt ) { SqlPipe pipe; pipe = SqlContext.Pipe; if (TestInt.IsNull) { pipe.Send("NULL value passed"); } else { pipe.Send(TestInt.ToString()); } } These commands execute as expected, and print "1" and

Convert Binary Id Field to Text

拟墨画扇 提交于 2019-12-21 18:39:16
问题 I need the text (representation) of a id field in SQL Server 2005. Is there a way, we can generate the textual representation of the id field? For instance, if the id field reads as 0x00000000000002F0, I need the text value of 0x00000000000002F0 so that I can run SUBSTR operations on the same. Constraints I am not allowed to create a stored procedure in the Database (as creation of SP is not allowed) Thanks! 回答1: You can convert unicode strings to binary using SELECT CONVERT(VARBINARY(40),N