sql-server

How to check a delete / upadate operation completed successfully, using stored procedure ?

Say we have stored procedure(s) performing simple operations CREATE PROCEDURE [dbo].[AddNewAuthorReturnID] ( @Author_Name VARCHAR(MAX), @Author_ID int OUTPUT ) AS SET NOCOUNT OFF; BEGIN INSERT INTO AUTHORS (@Author_Name) VALUES (@Author_Name) SET @Author_ID = SCOPE_IDENTITY() SELECT @Author_ID END in above procedure...

Need to update table row from UDF in SQL Server

I am using a function in the view for getting some result sets. In that function, based on some condition need to update rows to the database table. Can anyone tell me, How can I do this ...

inserting if in a select query

How can i do something like this ? SELECT (IF(SUM(Costo) > 0) SUM(Costo) ELSE 0) AS Expr1 FROM TDP_NotaSpeseSezB ...

How can remove lock from table in SQL Server 2005?

I am using the Function in stored procedure , procedure contain transaction and update the table and insert values in the same table , while the function is call in procedure is also fetch data from same table. i get the procedure is hang with function. Can have any solution for the same? ...

Moving a Point along a Path in SQL Server 2008

I have a geography field stored in my database, holding a linestring path. I want to move a point n meters along this linestring, and return the destination. For example, I want the destination point 500 meters along the linestring starting from its beginning. Here's an example -- what is the YourFunctionHere? Or, is there another w...

Populating droplist in ASP.NET with SQL Server takes a long time. Any optimizations?

One of my web pages populates a droplist with about 60k items pulled from SQL Server, and this operation takes upwards of 10 seconds to complete. Are there some tricks or optimizations I can try to improve performance? I'm using a SqlDataSource configured as a DataReader. Thanks for any help. ...

How to find largest objects in a SQL Server database?

How would I go about finding the largest objects in a SQL Server database? First, by determining which tables (and related indices) are the largest and then determining which rows in a particular table are largest (we're storing binary data in BLOBs)? Are there any tools out there for helping with this kind of database analysis? Or ar...

Is it possible to package dot net nuke custom module with database script?

i have made a custom module on DNN and create its package but when i integrate it with some other DNN application i need to manually create its required database to make that module working with that site. Is it possible to create a package in a manner that it can automatically create its database when integrate it with other applicatio...

When is a good situation to use a full outer join?

I'm always discouraged from using one, but is there a circumstance when it's the best approach? ...

Design Tables to hold multi-Country data

We're becoming an international company and I have been tasked with designing how we're going to store the different countries' specific data. Such as language, postal code regex, telephone number regex, country calling codes, currency, etc. Currently we have tables like these: Countries, Languages, CountryLanguages, CountryCallingCod...

SQL Server - alter column - adding default constraint

I have a table and one of the columns is "Date" of type datetime. We decided to add a default constraint to that column Alter table TableName alter column dbo.TableName.Date default getutcdate() but this gives me Incorrect syntax near '.'. Does anyone see anything obviously wrong here, which I am missing (other than having a better...

How to add database script in DNN custom module development package?

Hi,i have made a custom module on DNN ,created its package and integrated with another DNN application.It works fine.But after uploading the module in another DNN application i am creating module database manually.thats what my problem.. I want to create a module package with its database script.so that when end user upload my module th...

SQL script to "copy" a database

Hi, I want to write a SQL script that will copy a database on the same server. I could do a backup/restore, but I think it might be faster to just "copy" somehow. Does anyone know if this is possible? Is there a way to write a script that will just detach, copy the file on the HD, and then reattach both copies? ...

How I select a table sorted as a "Queue"?

I need to select a table sorted as a "Queue", the least recent to most recent row. Exists something feature that enable me to do this? ...

Preserving SQL DateTime format when reading from database

I have a very simple tool that runs a stored procedure from a database, puts the results into a DataTable, then writes the DataTable to a file via Response. The purpose is to take the data from a table on SQL Server, then use a 3rd-party tool to upload it to an Oracle database. The problem I encounter is that date is stored, in SQL Serv...

In SQL, how do I allow for nulls in the parameter?

I have what seems to be a really easy SQL query I can't figure out and its driving me nuts. This is SQL 2008. Basically, there is a status field where the can pick "pending", "satisfied" or all. If they send in "pending" or "satisfied" there's no problem. But when they pick all I'm having problems. Mostly because I can't figure out how ...

TSQL - Use a Derived Select Column in the Where Clause

Is there a way in TSQL to do something like this: select a,b,c, case when a=1 then 5 when a=2 then 6 end as d from some_table where d=6 The actual case statement is really complex, so I'm trying to avoid repeating it in the where clause? Are there any tricks to do this? (I think there's a trick in MySQL to use "having d=6"). ...

How to split space delimited field into rows in SQL Server?

I found this function which returns three rows for the following query: select * from dbo.split('1 2 3',' ') However, I need to use values from a field instead of '1 2 3'. I tried: select * from dbo.split(select top 1 myfield from mytable,' ') But it fails saying incorrect syntax. Ideas on how to do this? It doesn't have to u...

Selecting data from one table while storing (inserting) in two?

I want to copy data to a new database. However another table is included in the process where data should be put. Old table: DB1.dbo.pages (id, title, content) New table(s): DB2.dbo.Page (id) DB2.dbo.Content (id, pageid, title, content) How can I select all data from pages while splitting/storing it in Page and Content? ...

Datareader skips first result

I have a fairly complex SQL query that pulls different types of products from a database based on a customer ID. It pulls three different types of products, identified by their unique identifier number ranges (i.e., IDs 1000-1999 are one type of product, 2000-2999 are another, and 3000-3999 are yet another). SELECT b.fldMachineName, m2....