sql-server-2005

How to map uint in NHibernate with SQL Server 2005

你离开我真会死。 提交于 2020-01-11 09:10:30
问题 I have a property of type uint on my entity. Something like: public class Enity { public uint Count {get;set;} } When I try to persist that into the SQL Server 2005 database, I get an exception Dialect does not support DbType.UInt32 What would be the easiest way to workaround this. I could for example store it as long in the DB. I only don't know how to tell that to NHibernate. 回答1: The cleanest, most official solution would probably be to write a user type. Take an example, like this one and

C# ASP.Net: Exception (some times only) during long database operation

我的梦境 提交于 2020-01-11 07:47:08
问题 We have a ASP.Net web application that connects to its business layer using WCF. Sometimes, I am getting exception when it is performing a huge operation. The interesting part is when I ran it for the first time it was successful. Afterwards it is throwing exception. Exception: The socket connection was aborted. The operation is that it uploads zipcodes into database tables from a csv file. First we read from csv file and make a single lengthy string of zipcodes. This is passed to the stored

Get number of weekends between two dates in SQL

好久不见. 提交于 2020-01-11 06:49:07
问题 I need to get the number of weekends between dates in sql as a function. I have tried but stuck up somewhere in the logic. CREATE FUNCTION fnc_NumberOfWeekEnds(@dFrom DATETIME, @dTo DATETIME) RETURNS INT AS BEGIN Declare @weekends int Set @weekends = 0 While @dFrom <= @dTo Begin If ((datepart(dw, @dFrom) = 1)) Set @weekends = @weekends + 1 Set @dFrom = DateAdd(d, 1, @dFrom) End Return (@weekends) END 回答1: Try replacing the if statement with this: If ((datepart(dw, @dFrom) = 1) OR (datepart(dw

How do I read a large file from disk to database without running out of memory

白昼怎懂夜的黑 提交于 2020-01-11 06:18:09
问题 I feel embarrassed to ask this question as I feel like I should already know. However, given I don't....I want to know how to read large files from disk to a database without getting an OutOfMemory exception. Specifically, I need to load CSV (or really tab delimited files). I am experimenting with CSVReader and specifically this code sample but I'm sure I'm doing it wrong. Some of their other coding samples show how you can read streaming files of any size, which is pretty much what I want

Dynamically name indexes in SQL Server 2005?

*爱你&永不变心* 提交于 2020-01-11 04:55:20
问题 As most people who work with Sql Server know, you can declare a temporary table like so: create table #foo ( row_id int identity not null primary key, bar varchar(50) not null default 'YoMomma' ); ...this will create a primary key and a default constraint on this temporary table; the names for these objects will be unique, dynamically created by Sql Server. Is it possible to create a dynamically named index for the table after it's been created? I have a case where a stored procedure using

How to split strings in SQL Server

 ̄綄美尐妖づ 提交于 2020-01-11 04:21:05
问题 I have the following input: Data ----- A,10 A,20 A,30 B,23 B,45 Expected output: col1 Col2 ---- ----- A 10 A 20 A 30 B 23 B 45 How can I split the string to produce the desired output? 回答1: SELECT substring(data, 1, CHARINDEX(',',data)-1) col1, substring(data, CHARINDEX(',',data)+1, LEN(data)) col2 FROM table 回答2: I know the points has already been given, going to post it anyway because i think it is slightly better DECLARE @t TABLE (DATA VARCHAR(20)) INSERT @t VALUES ('A,10');INSERT @t

How do I remove “duplicate” rows from a view?

只愿长相守 提交于 2020-01-11 03:27:05
问题 I have a view which was working fine when I was joining my main table: LEFT OUTER JOIN OFFICE ON CLIENT.CASE_OFFICE = OFFICE.TABLE_CODE. However I needed to add the following join: LEFT OUTER JOIN OFFICE_MIS ON CLIENT.REFERRAL_OFFICE = OFFICE_MIS.TABLE_CODE Although I added DISTINCT , I still get a "duplicate" row. I say "duplicate" because the second row has a different value. However, if I change the LEFT OUTER to an INNER JOIN , I lose all the rows for the clients who have these "duplicate

Selecting most recent date between two columns

对着背影说爱祢 提交于 2020-01-10 12:03:06
问题 If I have a table that (among other columns) has two DATETIME columns, how would I select the most recent date from those two columns. Example: ID Date1 Date2 1 1/1/2008 2/1/2008 2 2/1/2008 1/1/2008 3 1/10/2008 1/10/2008 If I wanted my results to look like ID MostRecentDate 1 2/1/2008 2 2/1/2008 3 1/10/2008 Is there a simple way of doing this that I am obviously overlooking? I know I can do subqueries and case statements or even write a function in sql server to handle it, but I had it in my

SQL Server 2005 Using CHARINDEX() To split a string

和自甴很熟 提交于 2020-01-10 10:22:43
问题 How can I split the following string based on the '-' character? So if I had this string: LD-23DSP-1430 How could I split it into separate columns like this: LD 23DSP 1430 Also, is there a way to split each character into a separate field if I needed to (without the '-')? I'm trying to find a way to replace each letter with the NATO alphabet. So this would be..... Lima Delta Twenty Three Delta Sierra Papa Fourteen Thirty.... in one field. I know I can get the left side like this: LEFT(@item,

DATENAME(MONTH,GETADATE()) is returning numeric value of the month as '09'

故事扮演 提交于 2020-01-10 04:28:18
问题 When I run the following query [SELECT DATENAME(MONTH,GETDATE())], ideally speaking it should return value as 'September' but its returning value as '09'. I am running this query on MS SQL Server 2005. Is there anything I need to configure with MS SQL Server 2005? Please find the details of the SQL Server 2005 Component Name Version -------------------------------------------------------------------- Microsoft SQL Server Management Studio 9.00.1399.00 Microsoft Analysis Services Client Tools