sql-server-2005

Recursive function in sql server 2005?

烂漫一生 提交于 2019-12-29 01:48:12
问题 Can anybody suggest programming examples that illustrate recursive functions? For example fibonacci series or factorial.. 回答1: Here are a few articles that I found using google.com ;) Recursion in T–SQL Using recursion in stored procedures A Recursive User-Defined Function (SQL Server 2000) 回答2: Search for "common table expressions." See also this link Update Adding example from the above-referenced link: ;WITH Fibonacci(n, f, f1) AS ( -- This is the anchor part -- Initialize level to 1 and

Data is not inserting into table?

纵然是瞬间 提交于 2019-12-29 01:26:13
问题 My table name is Customer . It has four columns CustomerId CustomerName CustomerAddress PhoneNo This is my c# code. I am not getting any exceptions and data is not inserting into database. string connString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VictoryDatabase.mdf;Integrated Security=True;User Instance=True"; SqlConnection myConnection = new SqlConnection(connString); try { myConnection.Open(); string query = "insert into Customer(CustomerName,CustomerAddress,PhoneNo)

How do I call a User Defined Function to use with select, group by, order by?

杀马特。学长 韩版系。学妹 提交于 2019-12-28 20:35:30
问题 I have Table1 and I need to get it to look like Table2: Table1 VisitingCount | Date ----------------------- 1 | 15:09 3 | 15:10 7 | 15:15 1 | 15:39 2 | 15:40 3 | 15:47 Table2 VisitingCount | Date ----------------------------- 11 | 15:00-15:30 6 | 15:30-16:00 I wrote a sql user-defined functions like this: create FUNCTION [dbo].[fn_GetActivityLogsArranger] (@time AS nvarchar(max)) RETURNS nvarchar(max) AS BEGIN declare @Return varchar(30) select @Return = case when @time between '15:00' and

DataBinding: 'System.Data.DataRowView' does not contain a property with the name

无人久伴 提交于 2019-12-28 20:32:16
问题 I am getting this weird error... the primary key in my database is 'DocumentID' so I know that is not the issue. I am trying to get the select,edit & delete gridview buttons to work but I need the datakeynames to be set correctly for them to be available to use. any ideas? <asp:GridView ID="GridView1" runat="server" DataSourceID="sdsDocuments" EnableModelValidation="True" SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="DocumentID, DocumentTitle,

SQL 2005 CTE vs TEMP table Performance when used in joins of other tables

[亡魂溺海] 提交于 2019-12-28 13:47:11
问题 I have a complex query that I need to use in a subsequent query (actually update statement). I have tried both using a CTE and a temp table. The performance using the CTE is horrible vs the temp table approach. Its something like 15 seconds vs milliseconds. To simplify the test instead of joining the CTE/Temp table in the subsequent query I simply selected * from it. In that case they perform the same. I Have Looked at The Execution Plan for both approaches both with the joins in the

SQL Server list of insert identities

霸气de小男生 提交于 2019-12-28 13:46:10
问题 I have a table with an autoincrement id that I am doing a INSERT INTO ( ... ) SELECT ... FROM ... Is there a way for me to get the list of id's that have been inserted? I was thinking I could get the max id before the insert then after and assuming everything in between is new, but then if a row gets inserted from somewhere else I could run into problems. Is there a proper way to do this? I am using SQL Server 2005 回答1: Use the output clause. DECLARE @InsertedIDs table(ID int); INSERT INTO

Cross Domain SQL Server Logins Using Windows Authentication

人盡茶涼 提交于 2019-12-28 05:27:24
问题 I have a SQL Server 2005 named instance using Windows Authentication with domain groups serving as logins. The domain structures are as follows: Forest1 Forest2 / \ | Domain1 Domain2 Domain3 Objects are organized in the following domains: Forest1.Domain1 Users Global Groups Forest1.Domain2 SQL Server Instance Domain Local Groups (serving as Logins) Forest2.Domain3 Users Global Groups All my users exist in Domain1 and Domain3 but the SQL Server box exists in Domain2 . As such, my logins are

Linq to Entities : using ToLower() on NText fields

£可爱£侵袭症+ 提交于 2019-12-28 04:23:06
问题 I'm using SQL Server 2005, with a case sensitive database.. In a search function, I need to create a Linq To Entities (L2E) query with a "where" clause that compare several strings with the data in the database with these rules : The comparison is a "Contains" mode, not strict compare : easy as the string's Contains() method is allowed in L2E The comparison must be case insensitive : I use ToLower() on both elements to perform an insensitive comparison. All of this performs really well but I

Bulk insert fixed width fields

99封情书 提交于 2019-12-28 04:20:34
问题 How do you specify field lengths with the Bulk Insert command? Example: If I had a table named c:\Temp\TableA.txt and it had: 123ABC 456DEF And I had a table such as: use tempdb CREATE TABLE TABLEA( Field1 char(3), Field2 char(3) ) BULK INSERT TableA FROM 'C:\Temp\TableA.txt' SELECT * FROM TableA Then how would I specify the lengths for Field1 and Field2? 回答1: I think you need to define a format file e.g. BULK INSERT TableA FROM 'C:\Temp\TableA.txt' WITH FORMATFILE = 'C:\Temp\Format.xml'

Querying Active Directory from SQL Server 2005

你说的曾经没有我的故事 提交于 2019-12-28 04:04:23
问题 How can I query Active Directory from SQL Server 2005? 回答1: Pretty general question but here are some pointers. You need a linked server creating on the SQL Server that points to ADSI (Active Directory Service Interface) something like this will do it. EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource' Then you can use the following sort of query. SELECT * FROM OPENQUERY(ADSI, 'SELECT sAMAccountName FROM ''LDAP://DC=MyDC,DC=com,DC=uk'' WHERE