sql-server-2008

How to capture/encode special character for SQL Server in java app?

I have a java app + SQL server database. DB operation use JDBC with dynamic SQL string. Example: Select Column from tab where column=StringParm StringParam is user input. if the stringParm include apostrophe, Java app will throw exception and said Can't execute the SQL. How to resolve this problem with no java code changing? ...

Pass Arrays to SQL Functions from .NET C#

Hi, There is any chance to pass arrays to SQL Functions from .NET C#. Thanks in advance. Sincerely. And Could you show me how ? ...

Balancing different types of result records limited by a TOP 100

Given a table Records with the columns id int, Type int and Name varchar(50), I can make search queries like so: SELECT id, Type, Name FROM Records WHERE Name LIKE '%Foo%' To tweak the performance a little, I'd like to give only a limited amount of results; currently 100 — simply by adding TOP 100 to the statement. This, however, can ...

Select TOP N and set variable if more could be selected

Is there a more efficient way of doing the following SQL? I want to select the top 50 results, but I also want to set a variable to tell me if I would have gotten more results back without the TOP DECLARE @MoreExists BIT SET @MoreExists = 0 DECLARE @Count INT SELECT @Count = Count(*) FROM MyTable WHERE ... --some expensive where ...

SSIS SQL 2008 setting a collection property

In SQL 2008 the Backup Database Maintenance Plan Task has a collection property called "SelectedDatabases" I would like to pass a single value database name to this property. However the property requires a collection not a string. Is there anyway I can return a collection from the Expression Builder to achieve this. ...

Datatype not supported in SQL Server 2008 while creating trigger

Which Datatypes are not supported in SQL Server 2008 while creating trigger ...

Why does a datetimeoffset have 28 hours of timezones?

I am looking into using the datetimeoffset for SQL Server 2008. According to the MSDN article there is a time zone offset range of -14:00 through +14:00. I can understand going 12 hours from UTC in each direction, one hour per timezone. I think I understand 13 hours in each direction, for daylight savings time. I just dont get 14 hours? ...

The SELECT permission was denied on the object 'Address', database 'CNET_85731', schema 'dbo'

Hi Group, I have been working away for the last 7 months on a C# ASP.NET using Visual Studio 2008 and SQL Server 2008. Today, I was running part of my application which was previously running and I got the following error: The SELECT permission was denied on the object 'Address', database 'CNET_85731', schema 'dbo'. I walked through ...

deleting databases in sql server

I need to delete databases whose name start with "In"... I Tried "Like" but it is throwing syntax errors... I tried following command but throwing syntax errors for "name" SELECT 'DROP DATABASE ' + name + ';' from sys.databases where name like 'In%' ...

Using "SELECT SCOPE_IDENTITY()" in ADODB Recordset

Using a VBA script in Excel, I'm trying to insert a new row into a table and then get back the identity value of that row. If I run: INSERT INTO DataSheet(databaseUserID, currentTimestamp) VALUES (1, CURRENT_TIMESTAMP); SELECT SCOPE_IDENTITY() in Management Studio, the row is inserted and it gives me the returned identity value as exp...

TSQL: How to convert local time to UTC? (SQLServer2008)

We are dealing with an application that needs to handle global time data from different time zones and daylight savings time settings. The idea is to store everything in UTC format internally and only convert back and forth for the localized user interfaces. Does the SQL Server offer any mechanisms for dealing with the translations given...

In SQL Server how to give only "read only" permission to all DB objects?

I need to give read only permission to a couple of users on the database so that they can get an understanding of the schema, logic in SPs, etc. But I do not want them to modify anything. I tried assigning the db_datareader role but it doesn't allow viewing SP name or code. What is the right role-combination to do this or do I need to wr...

does log4net AdoNetAppender support sql server 2008???

Hi, my config file below: very strange, i have spent a day to find out where i am wrong, but still not working, it still not log anything in the database,but i can output them using RollingFileAppender. Also, the store procedure WriteLog is working well.(I have tested it using sql server studio). I have tried to change the connectionTyp...

With SQL2008 Spatial functions, How can I generate a polygon containing the results of an aggreation

I've got a table of points, each with a name, latitude, longitude, and an area code. What I'd like to do is perform an aggregation (i.e. a "group by" clause) and return a polygon containing all the points for a particular area code. I'm struggling a little to even find if there are any built in aggregations for the geography data types...

Why is the DataAdapter not getting error thrown by trigger

I have a trigger on a view that handles update operations. When I use the MS Management Studio and do an insert I get this error: Msg 50000, Level 16, State 10, Procedure Trigger_TempTableAttr_Lot_UpdateDelete, Line 166 Violation of UNIQUE KEY constraint 'UK_Lot_LotAccountCode'. Cannot insert duplicate key in object 'app.Lot'. Msg 3616,...

Looking for good sql server 2008 reference or general help

Hi Is anyone know any good reference or general help for sql server 2008 ? thank's in advance ...

DateDiff in SQL Server asking for help

Hello everyone, I am using SQL Server 2008. I have a table which has a datetime type column called CreateTime. I need to select all the records from this table whose CreateTime is more than 3 days and half an hour from current time (UTC time). I am using T-SQL store procedure. BTW: The CreateTime column is some time in the past time. ...

how to execute a stored procedure in a SQL Agent job?

I am using SQL Server 2008 and I need to run a SQL Job from SQL Server Agent. I am new to SQL Server Job and I want to execute a stored procedure regularly from a SQL Server Job. But I did not find where to specify the executed stored procedure other than copy & paste SQL commands. Here is my screen snapshot, Any ideas how to assign ...

Any solutions to test SQL Agent Job immediately to ignore schedule

Hello everyone, I am using SQL Server 2008 and I want to test the execution correctness of my SQL Server Agent job immediately to ignore the schedule. Any ideas? thanks in advance, George ...

Insert record and return Id in a SQL UDF??

I need a user defined function to insert a new record and return the Id, is this possible and how do I do it? I have tried creating a function with the insert statement but I am getting the following error: Invalid use of the side-affecting operator 'INSERT' within a function. I am using SQL server 2008. UPDATE SQL: CREATE FUNCTION...