sql-server

how to structure an index for group by in Sql Server.

Hi, The following simple query takes a very long time (several minutes) to execute. I have an index: create index IX on [fctWMAUA] (SourceSystemKey, AsAtDateKey) SELECT MAX([t0].[AsAtDateKey]) AS [Date], [t0].[SourceSystemKey] AS [SourceSystem] FROM [fctWMAUA] (NOLOCK) AS [t0] WHERE SourceSystemKey in (1,2,3,4,5,6,7,8,9) GROUP BY [t0...

how to write number to word function in sql server

How would one write a function in SQL Server to output a number in words? input: 1 output: one input: 129 output: one hundred twenty-nine ...

Sql date field is not getting saved exactly

Hi, I am trying to insert a date value '2010-03-14 02:00:00 AM'(Day light saving start time for 2010 year) in a datetime field of a table in sql server 2005. The date is saved as '2010-03-14 03:00:00 AM' The server is installed in US(EST time zone). Can anyone tell me the reason why the date is saving differently? Thanks Rupa ...

SQL Server text column affects results returned to classic ASP

Using classic asp, I am trying to query a SQL Server database like so: strSQL = "select column_1, column_2, column_3, column_4 from someview " &_ "where RecordNo=" & i set rs=conn.Execute(strSQL) if not rs.eof then A = rs("column_1") B = rs("column_2") C = rs("column_3") D = rs("column_4") end if Column_3 is...

sql / linq to entities: group on group of hours

Hi, i have a table with snow data which i get delivered per hour. so for instance at between 0am and 1 am 1 cm snow will fall, between 1 am and 2 am 3 cm snow will fall, between 2 am and 3 am 0 cm snow will fall, between 3 am and 4 am 2 cm snow will fall etc. so the table has a Snowdate column (datetime), a Snowdate hour column (int) an...

How to save an image from SQL Server to a file using SQL

Question In SQL Server 2005, I have a table with images (data type: image). Using only SQL, how do I save an image as a file (on the same server that SQL Server is running). If I have to, I'll use SQL CLR, but I want to avoid that if possible. Background I want a SQL Server job to run no a schedule that calls a proc that will send ema...

Many connections vs. big data queries

Hello I am creating a windows application that will be installed in 10 computers that will access the same database thru Entity Framework. I was wondering what's better: Spread the queries into packets (i.e. load contact then attach the included navigation properties - [DataContext.Contacts.Include("Phone"]). Load everything in one qu...

Acess 2007 adp project with SQL Server 2005 Express database

Hello Everyone, I have a strange problem with an Access adp project. There is a main form with a header and a details sections on a page. The detaisl section is made up of a tab control that has 7 tabs to it. Only the 1st tab shows up if I connect the project to a REMOTE SQL Server 2005 Express database. The same details section w...

Creating an efficient search capability using SQL Server (and/or coldfusion)

I am trying to visualize how to create a search for an application that we are building. I would like a suggestion on how to approach 'searching' through large sets of data. For instance, this particular search would be on a 750k record minimum table, of product sku's, sizing, material type, create date, etc; Is anyone aware of a 'plu...

Setting single user mode to restore backup.

I have the following function: public void RestoreDatabase(String databaseName, String backUpFile, String serverName, String userName, String password) { SqlConnection.ClearAllPools(); ServerConnection connection = new ServerConnection(serverName, userName, password); Server sqlServer = new Server(connection); Restore rs...

Returning data from database in .net: Return a DataTable or LIst<T>?

I'm struggling with bridging the concepts of good database design with good object orientated design. Traditionally if I wanted to display a list of news stories in a repeater, I would use something like: <script runat="server"> void ShowNews() { rptNewsStories.DataSource = News.GetAllNews(); // Returns a DataTable r...

SQL Server: Count how big a column value is compared to the others

I have table column filled with float values e.g.: id-Values 1- 0.19230769230769232 2- 8.4848484848484854E 3- 0.10823529411764705 4- 0.05459770114942529 ... I would like to know: is there a SQL function that allows me to return a percentage of the selected row position compared to the others? For example: I want to kno...

Using XML, XSLT and c# to create an RTF or PDF

EDIT: User has informed me that he will accept PDF format also I have to create a simple RTF or PDF document in server side code and save on a network driver for future downloading. The letter will be populated from info that I have stored in a SQL Server (2005). I access the databse using a Linq-to-Sql model. The document will be ...

SQLServer 2008 generic column type

Hi, I've a table on SqlServer where a column type should be undefined, I mean, it should be able to contain any kind of type (string, int, boolean and datetime). This because my users should be able to define which type the column is for each record. In the past when I encountered this problem I decided to create it as nvachar(MAX). Wh...

SharePoint use of windows identity and connection pooling

When a user accesses a SharePoint site he is identified by his wndows identity. I was wondering which identity is used to access the database. Is it the identity of the user or does it use the windows identity of a service, or order to gain the benefits of connection pooling. Thanks Shiraz ...

Using if exists

I'm having an issue with duplicates being inserted on refresh. Our team here decided using 'if exists' in sql is the best way to stop duplicate inserts. However, what if a parameter is set to null? string cmdText = " if (not exists(select * from table where field1 = @field1 and field2 = @field2 and field3 = @field3)) Insert into table(f...

ReportBuilder2 + SQL 2000

Should ReportBuilder 2 be capable of listing views when connecting to a SQL 2000 database? ...

Can 2 update or insert triggers be created on the same table in SQL Server 2008?

Can 2 update or insert triggers be created on the same table in SQL Server 2008? ...

SQL Return Unique data

Hi, I have a table that looks like this: id, col1, col2 col3 0 "Goat" "10" "0" 1 "Cat" "11" "0" 2 "Goat" "12" "1" 3 "Mouse" "13" "0" 4 "Cat" "14" "2" I want be able to return the UNIQUE values in Col1 AND if there are two identical values in col1 then use col3 to decide which value to use i.e. if i...

How to run a stored procedure every day in SQL Server Express Edition?

How is it possible to run a stored procedure at a particular time every day in SQL Server Express Edition? Notes: This is needed to truncate an audit table An alternative would be to modify the insert query but this is probably less efficient SQL Server Express Edition does not have the SQL Server Agent Related Questions: How can ...