sql-server

Linking tables between databases

Hi, I’m after a bit of advice on the best way to go about this is SQL server 2008R2 express. I have a number of applications that are in separate databases on the same server. They are all “plugins” that use a central staff/structure list that will be in a separate database. The application is in the process of being migrated from JET. ...

SQL Server - Setting Multiple Values in a Case Statement?

Hi, I have a SQL Select statement where I need to return certain values depending on a condition. I need to return multiple values each time, but my understanding of the Case statement is that you can only return a single value for each case. I'm getting around this by using UNION statements at the moment, but it all looks a bit cum...

how to solve this problem? java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) a...

sql: compare 2 strings without considering accents and other stuff îăţş = iats (<-should be equal)

I need to compare 2 strings in sql so that the word "iast" would be equal to "îăşţ" anybody knows how to do this ? ...

How to get the time in hours between these two dates

Hi Guys, I have one table in that they are four coumns like startdate varchar(15), enddate varchar(15), starttime varchar(15), endtime varchar(15) Here I need to get the time in hours between these two dates (ex: 6/7/2010,6/12/2010) if i pass these days as inputs regards, ravi ...

Connecting to an external SQL Database from within SharePoint code

I have some event handlers which are tracking list items in my SharePoint lists. I would like to Audit the use of these in an external database (SQL 2005) outside of SharePoint. What is the best practice for doing something like this? I can't find many examples of this being done but it seems like it would be something that is done freq...

SQL Server Table Names Containing Leading '__' Characters.

In SQL Server 2005/2008, is there some significance to tables that have two leading underscore characters in their name? For example, a tool we use to manage our database creates a table named dbo.__RefactorLog, if it currently doesn't exist. I cannot see this table in SSMS, and Red-Gate SQL Compare doesn't seem to see it either. Thanks...

Sql Like to RegEx

Hi, Is there a good way to convert Regular Expression into LIKE inside a Function (MSSQL)? The sproc does not get more complicated than this: (country\=)(?<Country>[\w\d]+)(\&sessionid\=)(?<SessionId>.+) The groups will not be used in the LIKE, they are there for another purpose. I would like to use this inside a sproc late like: ...

is it possible to log events of ssis package execution using c# to a file

Hi, Is it possible to log the events of ssis package execution called from c# Application app = new Application(); Package package = app.LoadPackage("<package_path>", null); package.ImportConfigurationFile("<configuration_path>"); DTSExecResult result = package.Execute(); I need to log the messages generated during the package exe...

WiX issue with executing SqlScript at the remote DB

Hi there, Executing SqlScript at the remote DB causes an error: Failed to connect to SQL database. (-2147467259 myDB1) The SqlScript is the following: <sql:SqlString Id='UpdateSomething1' SqlDb='myDB1' ExecuteOnInstall='yes' User='SQLUser' ContinueOnError='no' ExecuteOnReinstall='no' ExecuteOnUninstall='no' Sequence='26' SQL='...

Error While Copying database from SQL server 2005 to SQL server 2008 using Import wizard

I am getting the following error when I am trying to copy database and it's getting stopped at this point. Error 0xc0047008: Data Flow Task 46: The package contains two objects with the duplicate name of "output column "ErrorCode" (720)" and "output column "ErrorCode" (737)". Warning 0x80019002: Data Flow Task 46: SSIS Warning Code DTS...

How to determine disk space used by an Indexed view in SQL Server 2005.

Is there a way to determine how much disk space is used by an Indexed/Materialized View? ...

How much performance do I lose by increasing the number of trips to SQL Server?

I have a web application where the web server and SQL Server 2008 database sit on different boxes in the same server farm. If I take a monolithic stored procedure and break it up into several smaller stored procs, thus making the client code responsible for calls to multiple stored procedures instead of just one, and I going to notice ...

Year Based Primary Key?

How can I create a Primary Key in SQL Server 2005/2008 with the format: CurrentYear + auto-increment? Example: The current year is 2010, in a new table, the ID should start in 1, so: 20101, 20102, 20103, 20104, 20105... and so on. ...

How do I put textarea data into an SQL Server database?

(This is classic ASP) I'm sure this is just a case of escaping the text, but I haven't found anything yet. I have a textarea that may contain all sorts of characters and I need to UPDATE the record with whatever is in that textarea, but I'm getting an error that breaks my SQL query, which I'm positive is related to the content of the tex...

What's the fastest method to check SQL server availability?

What's the best method to check if SQL server exists or not? I'm trying Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion() and it works fine if server exists and available. But it kinda pretty slow, if there is no such a server. Is there any fast enough method to check without even defining user credentials (only the se...

Does SQL Server accept special characters?

Does SQL Server handle ASCII codes such as NUL, LF (line feed), CR (carriage return), space, etc? I would like to know because I have a file from mainframe that contains special characters which I need to export to SQL Server as a text file. When I view the records (at the back end as hex code) in SQL Server I want to see those special c...

One-to-Many Table Join?

I have one table (webRooms) which has a number of rows which match those in a second table (Residency). Table 1 looks like this: ID | dorm_building | dorm_room | occupant_num Table 2 looks like this: student_ID | dorm_building | dorm_room What I'd like is to get results like this: ID | dorm_building | dorm_room | o...

SQL Query to get latest user comment per blog post limited to one for each user?

I have multiple users submitting comments on multiple blog posts. Users can comment multiple times on each blog post. I need a SQL Query (sql server 2008) to get the last comment for each User given a BlogPostId. Lets say 3 users submit a total of 10 comments on a specific blog post. For Blog Post #1, User A has submitted 5 comments,...

How can I generate database tables from C# in order to version control the database?

Currently, changes to the database are made through the SQL Server Management program. IF a table changes, sqlmetal is run to regenerate the linqtosql classes and development continues. However, this makes deployment a pain, as you have to go through and manually update the deployment database (and any other databases used in the devel...