sql-server-2008

SQL Server: How to iterate over function arguments

I'm trying to learn SQL and for demonstration purposes I would like to create a loop which iterates over function arguments. E.g. I would like to iterate over SERVERPROPERTY function arguments (propertynames). I can do single select like this: SELECT SERVERPROPERTY('ProductVersion') AS ProductVersion, SERVERPROPERTY('ProductLevel') AS P...

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '.

I am trying to query from a temp table and i keep getting this message: Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '. Can somebody tell me what the problem is? Is it due to convert? The query is select compid,2, convert(datetime, '01/01/' + CONVERT(char(4),cal_yr) ,101) ,0,  Update_dt, th1, th2, th3_pc , Update_id,...

How to escape forward slash?

I have the following sql command through code and because the parameter contains a forward slash when I evaluate the sql row after the update the column is just empty. sqlCommand.CommandText = String.Format("update {0} set {1}='{2}'where id = @Id", tableName, ColumnName, forwardSlashText); sqlComm...

database setup for web application

I have an application that requires a database and I have already setup tables but not sure if they match the requirements of the app. The app is a crawler which fetches web urls, crawls and stores appropriate urls and posts and all this is based on client requests which are stored as projects. So for each url stored there is one post an...

SQL Server 2008 - Search Query

Hello, I am not a SQL Expert. I’m trying to elegantly solve a query problem that others have had to have had. Surprisingly, Google is not returning anything that is helping. Basically, my application has a “search” box. This search field will allow a user to search for customers in the system. I have a table called “Customer” in my SQL...

SQL Query - Can I compare using LEN in SELECT clause?

I basically want to do this: SELECT HasComments = CASE (LEN(Comments) > 1) WHEN 1 THEN 1 ELSE 0 END FROM TableName In other words, return a boolean telling me whether the length of Comments is greater than 1. This gives me a syntax error. How can I accomplish this? ...

Java w/ SQL Server Express 2008 - Index out of range exception

Hi! I created a stored procedure in a sql express 2008 and I'm getting the following error when calling the procedure from a Java method: Index 36 is out of range. com.microsoft.sqlserver.jdbc.SQLServerException:Index 36 is out of range. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java...

Trying to Export Data from an unusal Access Database with Synonyms

We use a product called SalesOutlook which is a type of CRM system. I need to export data from this using SSIS or some other program. When you install the program, it creates a DSN on my system called SalesOutlookReports. It use the Microsoft Access Driver (*.mdb). When I try to look at it using Crystal Reports I see a list of tables...

How to create relationship between two tables with revisions using Entity Framework

So I am in the process of redesigning a small database (and potentially a much larger one) but want to show the value of using revisions / history of the business objects. I am switching the data from Access to MSSQL 2008. I am having a lot of internal debate on what version of "revision history" to use in the design itself - and thou...

Continous integration with Reporting Services

I'm implementing a continuous integration environment with SVN and reporting services. The reports are stored in the SVN repository. when a change occurs, they are automatically downloaded from the repository, and any file changed should be uploaded to the reporting services server. How could you automate the upload/update process for ...

SQL Server 2008 - create database script (schema + data) with command-line

In SSMS when click on database "Tasks -> Generate Scripts" I get an output script. How to make the same with non graphical tool? ...

casting odd smallint time to to datetime format.

Hello everyone, I'm working with a db (SQL server 2008), and have an interesting issue with times stored in the db. The DBA who originally set it up was crafty and stored scheduled times as smallints in 12-hour form-- 6:00AM would be represented as 600. I've figured out how to split them into hours and minutes like thus: select floor(t...

Auto Generated - CREATE Table Script in SQL 2008 throws error

I scripted the tables in my dev database using SQL 2008 - generate scripts option (Datbase->right click->Tasks->Generate Scripts) and ran it on the staging database, but the script throws the below error for each table Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '('. Msg 319, Level 15, State 1, Line 15 Incorrect sy...

Sql Server SMO connection timeout not working

I have the following PowerShell code: function Get-SmoConnection { param ([string] $serverName = "", [int] $connectionTimeout = 0) if($serverName.Length -eq 0) { $serverConnection = New-Object ` Microsoft.SqlServer.Management.Common.ServerConnection } else { $serverConnection...

Help with random - sql server 2008 query

hi i have 4000 records, and i need to pick randomize 500 records. i need that 500 records will insert to GoodTable and the rest 3500 records will insert to BadTable how to do it using sql-server 2008 query ? thank's in advance ...

Unable to connect SQL Server instance from Visual Studio 2008 Version 9.0

I am getting the below error from VS on an 32-bit XP Professional server even though I set Tools->Options->Database Tools->Data Connections to "SIDEKICK", which is the name of my computer. In other words SIDEKICK should default to the full SQLSERVER. In other words, I want VS to use SQLSERVER instead of SQLSERVER EXPRESS. And I can ...

SQL Server 2008 - Full Text Query

Hello, I have two tables in a SQL Server 2008 database in my company. The first table represents the products that my company sells. The second table contains the product manufacturer’s details. These tables are defined as follows: Product ------- ID Name ManufacturerID Description Manufacturer ------------ ID Name...

Cannot perform an ORDERBY against my EF4 data

I have a query hitting EF4 using STEs and I'm having an issue with user-defined sorting. In debugging this, I have removed the dynamic sorting and am hard-coding it and I still have the issue. If I swap/uncomment the var results = xxx lines in GetMyBusinesses(), my results are not sorted any differently - they are always sorting it ascen...

Using a set of numbers inside a database without creating a temporary table

I have a set of numbers and a table in a database with the id (primary key) and text (not null) columns. I would like to create a query that returns all the numbers in the set and the associated text from the table. Unfortunately not all numbers exist in the database's id column, so this won't work: select id, text from table where id i...

How to remove duplicate records in a table?

I've got a table in a testing DB that someone apparently got a little too trigger-happy on when running INSERT scripts to set it up. The schema looks like this: ID UNIQUEIDENTIFIER TYPE_INT SMALLINT SYSTEM_VALUE SMALLINT NAME VARCHAR MAPPED_VALUE VARCHAR It's supposed to have a few dozen rows. It has about 200,000, most of which are...