sql-server

SQL Server 2000 "Select is broken" with TOP clause

Using SQL Server 2000 Developer Edition, why would this code: select top 10 * from table result in this error: Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near '10'. and this code: select * from master m left join locality l on m.localityid = l.localityid result in this error: Server: Msg 170, Le...

Storing Multi Choice Field into in SQL Server 2008

I'm writing an app in .NET, and using a dropdown checkbox. I'm not sure what the best practice is for storing this info in the db. Currently I'm writing back a comma delimited string to an SP in SQL Server 2008 ie "apple, banana, pear", storing this in a nvarchar(MAX) and then splitting this in the SP into another table holding the ID ...

T-SQL: Why is my query faster, if I use a table variable?

Hello, can anybody explain me why this query takes 13 seconds: SELECT Table1.Location, Table2.SID, Table2.CID, Table1.VID, COUNT(*) FROM Table1 INNER JOIN Table2 AS ON Table1.TID = Table2.TID WHERE Table1.Last = Table2.Last GROUP BY Table1.Location, Table2.SID, Table2.CID, Table1.VID And this one only 1 second: D...

Updating the dataset into the database in C# .net

Hi, I am using a stored procedure to fetch the data from the database and populating the dataset with the output. I am trying to update some valued to the dataset that is populated. Now how do i update the modified dataset to the database. 1) Should i update the database by looping through the dataset rows? 2) Will dataadapter.Upda...

Truly empty element with sql server for xml-directive

How do I create a truly empty xml element with the for xml-directive in sql server (2005)? Example: select '' for xml path('element'), root('elements') Outputs: <elements><element></element></elements> But what I really want is: <elements><element /></elements> ...

Help in writing Query for hall booking date availability search

I need help in writing query to find the time slot availability for a hall booking system.. details are given below I have a Hall table which stores the hall details and HallBooking table which stores the start and from time of the bookings done.. Hall - HallId - Name HallBooking - HallBookingId - HallId - BookingPersonName - StartDat...

How can I set an alias name in SQL Server

IF RTRIM(@GLDD_LEDGER_CODE)= '00' BEGIN SELECT @SYS_REM =GLMA_ACCT_NAME FROM GLAS_GL_MASTERS WHERE GLMA_COMP_CODE = @COMP_CODE AND GLMA_LDGR_CODE = '00' AND GLMA_DEPT_NO = SUBSTRING(@GLDD_ACCT_CODE, 2, 2) AND GLMA_ACCT_CODE = SUBSTRING(@GLDD_ACCT_CODE, 4, 4) AND GLMA_YEAR = DATEPART(YYYY, GETDATE()) END ELSE BEGIN...

Unclosed connection - Connection Pool debugging SQL Server

We have a suspect application leaving a connection open. Just wondering on the debugging tools for this, as to whether anyone has any good tools for isolating this, commercial or otherwise. I've Googled but only seem to bring up articles that describe the problem - not the steps for a solution. This is the best article I've seen so f...

Retrieving list of Sql Server instances on the local PC and the network.

How can one determine which sql server instances are installed on the local machine and the network environment? ...

SQL Server Script to create a new user.

I want to write a script to create a admin user ( with abcd password )in SQL Server Express. Also I want to assign this user (admin) full rights ...

How to do the eqivalent of a 'Tsql select into', into an existing table

using tsql, sqlserver 2005. I would like insert records from table table2 into an existing table table1 as easily as I could enter it into a new table table1 using: select facilabbr, unitname, sortnum into table1 from table2 Any ideas? ...

Join instead of correlated subquery

CREATE TABLE BlogPosts ( PostID INT PRIMARY KEY not null, PostTitle NVARCHAR , BlogID int, TotalComments int ) May this query be simplified with any Join instead of correlated subquery? SELECT TOP 5 * FROM BlogPosts as t0 WHERE t0.PostID = (SELECT TOP 1 t1.PostID FROM BlogPosts as t1 WHERE t0.BlogID = t1.BlogID ORDER BY...

SQL Server Union of a single label header and a boat load of data columns

I have a SELECT * FROM #tmp and it returns 131 records. I wish to prepend this with a label so the result is format=transaction, followed by the rows each containing 131 columns. It is cumbersome to do the following; is there a nicer method? SELECT 'format=transaction', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,...

Cannot find the object "XXX" because it does not exist or you do not have permission.

I'm getting the following error when calling a stored procedure: Cannot find the object "XXX" because it does not exist or you do not have permission. I've checked the database and the SP is there with the correct permissions yet I'm still getting the error. Any suggestions? ...

Writing a complex trigger

This posting is an update (with trigger code) from my earlier posting yesterday I am using SQL Server 2000. I am writing a trigger that is executed when a field Applicant.AppStatusRowID Table Applicant is linked to table Location, table Company & table AppStatus. My issue is creating the joins in my query. When Applicant.AppStatusRow...

How do I return the SQL data types from my query?

I've a SQL query that queries an enormous (as in, hundreds of views/tables with hard-to-read names like CMM-CPP-FAP-ADD) database that I don't need nor want to understand. The result of this query needs to be stored in a staging table to feed a report. I need to create the staging table, but with hundreds of views/tables to dig through...

Hibernate on Oracle AND SQLServer

I'm introducing a DAO layer in our application currently working on SQL Server because I need to port it to Oracle. I'd like to use Hibernate and write a factory (or use dependency injection) to pick the correct DAOs according to the deployment configuration. What are the best practices in this case? Should I have two packages with dif...

Stored Procedure Timing out.. Drop, then Create and it's up again?

I have a web-service that calls a stored procedure from a MS-SQL2005 DB. My Web-Service was timing out on a call to one of the stored procedures I have (this has been in production for a couple of months with no timeouts), so I tried running the query in Query Analyzer which also timed out. I decided to drop and recreate the stored pro...

What is the best deployment approach for WPF applications with local database?

I want to make a WPF application that exists in one directory including all files that it needs: .exe, .mdf database, .xml config files, etc. the application should work no matter what directory it is in so that it supports this scenario: person 1 executes the application in c:\temp\wpftool.exe the application reads and writes to the c...

Batch commit on large INSERT operation in native SQL?

I have a couple large tables (188m and 144m rows) I need to populate from views, but each view contains a few hundred million rows (pulling together pseudo-dimensionally modelled data into a flat form). The keys on each table are over 50 composite bytes of columns. If the data was in tables, I could always think about using sp_rename t...