sql

Multiple synonym dictionary matches in PostgreSQL full text searching

I am trying to do full text searching in PostgreSQL 8.3. It worked splendidly, so I added in synonym matching (e.g. 'bob' == 'robert') using a synonym dictionary. That works great too. But I've noticed that it apparently only allows a word to have one synonym. That is, 'al' cannot be 'albert' and 'allen'. Is this correct? Is there any ...

What represents a double in sql server?

I have a couple of properties in c# which are doubles and I want to store these in a table in sql server, but noticed there is no double type, so what is best to use, decimal or float? This will store latitude and longitude values, so I need the most accurate precision. Thanks for the responses so far. ...

Get last record for each date from a table

I have a table that logs inventory updates throughout the day. Table InventoryHistory: UpdateID INT IDENTITY ProductID INT UpdateDateTime DATETIME QuantityOnHand INT Sample records: 1, 1, '7/29/2009 9:00', 100 2, 1, '7/29/2009 14:00', 99 3, 1, '7/29/2009 20:00', 98 4, 1, '7/30/2009 9:00', 97 For a given ProductID, I need to get a ...

SQL Design - Accounting for unknown values

Ok, this gets a little tricky. Here goes. Say I have a table called HoursCharged ChrgNum(varchar(10)) CategoryID(uniqueidentifier) Month(datetime) Hours(int) CategoryID is a foreign key reference to another table in my database, which is just a name/ID pairing. ChrgNum is guaranteed to be unique outside of this database, a...

How to retrieve rows multiple times in SQL Server?

These are my rows that I initially retrieved: 112 Cem Ceminay 210 Ali Salih 132 Gül Sen Now I want to clone every row to be duplicated as 3 rows. So the new results: 112 Cem Ceminay 112 Cem Ceminay 112 Cem Ceminay 210 Ali Salih 210 Ali Salih 210 Ali Salih 132 Gül Sen 132 Gül Sen 132 Gül ...

Is there a way to use SSIS to execute SQL statements that are stored in an Excel file?

I am using Excel to generate a whole slew of INSERT statements, similar to the process described here. I would like to have an SSIS package that will run through each row of this excel file and run the SQL statements it finds against a database. Is this possible? EDIT: As John points out - there is a better way to do it - generate th...

View all transaction logs in SQL Server 2008

The problem is this: t0: Insert is made into my database t1: Delete is executed t2: Full backup is made t3: Transaction log backup is made How can i recover the deleted record after t3 (which is now)? I want the database in a state between t0 and t1. The log level was Full. Edit: I have already run DBCC LOG(DB-Name, 3), but the log s...

Tips for deduping a list based on priority column

I have a set of rows that contain duplicate entries because the data originates from multiples sources. I also have a separate reference table that indicates the priority of those data sources. Does anyone have good tips for the most effective t-SQL to deduplicate this list? Basically I have: SELECT a.*, b.priority FROM tableA as a ...

Making a SQL Query More Efficient

I have a query along the lines of select b.* from (select key, max(val) as val from (somequery) group by key) as a inner join (somequery) as b on a.key = b.key and a.val = b.val order by key And I was wondering if there is an obvious way (that I am missing) to simplify it (given that somequery might be rather long). Any thoughts woul...

sql command for reading all columns in the first row

Dear All I am an SQL newbie, I am having an excel sheet in which the first row contains title for all the columns. I want to all the names in the first row. Question What is the SQL command for - reading all the entries in the first row? If possible, I want to define the max-limit. Addition: What I want is, "Enumerate all the column...

Function in SQL Select Statement

CREATE VIEW View1 AS SELECT Col1, Col2, dbo.fn1(col2) as Col3 FROM TestTable /* --Instead of writing below query I created a new View View2 SELECT Col1, Col2, dbo.fn1(col2) as Col3 dbo.fn2(dbo.fn1(col2)) as Col4 FROM TestTable */ CREATE VIEW View2 AS SELECT Col1, ...

Retain original value in DataBase when NULL value is passed to Stored Procedure

Hi I am a newbie in SQL and require help I have a parameterized stored procedure which contains a Update query like... UPDATE sometable SET price1 = @param1, price2 = @param2, price3 = @param3, price4 = @param4, WHERE ID = @param5 Now when I execute this SP by setting any of the parameters value as NULL it gets updated in DB, w...

Netezza SQL syntax to convert numeric YYYYMMDD format into date

We have a Netezza table that contains dates stored in a numeric YYYYMMDD format (eg 20090731). What is the best Netezza syntax to use to convert this into date format? eg SELECT somefunction(20090731) as NZDATE ? ...

Simulate a table creation with SQL

Hello. Is there a standard way to simulate a table creation in a database by using SQL? I don't want the table to be created, just check if it could be created. One way would be to create it and then delete it again. Any other way? ...

Need remove duplicate rows

I have an sql statement that gets repair orders and repair visits, howver i only want one particualr visit being pulled out but its pulling them all out and then duplicating the parts ordered, and i dont know what im doing wrong im sure there is really simple way round this but i dont know what is wrong with me today just cant see the ob...

Find the row associated with a Min/Max, without inner loop

Hi, I have a question related to T-SQL and SQL Server. Let's say I have a table Orders with 2 columns: ProductId int CustomerId int Date datetime I want the date of the first order for every product, so I perform this type of query: SELECT ProductId, MIN(Date) AS FirstOrder FROM Orders GROUP BY ProductId I have an index on Produc...

Check constraint to make sure values in a character column are all digits.

This is similar to http://stackoverflow.com/questions/1167767/check-constraint-of-string-to-contain-only-digits-oracle-sql but I want to do this for Sybase. I have a character column 'colExp' (8 characters). I want to put a check constraint to make sure values for this column are all digits. How can I do this? This will work but its n...

How do you group by one column and retrieve a row with the minimum value of another column in T/SQL?

So I know this is a pretty dumb question, however (as the rather lengthily title says) I would like to know how do the following: I have a table like this: ID Foo Bar Blagh ---------------- 1 10 20 30 2 10 5 1 3 20 50 40 4 20 75 12 I want to group by Foo, then pull out rows with minimum Bar, i.e. I want the following: I...

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...

How can I change a column's data type and then perform actions against that new type in the same script in SQL Server?

I have a script with an Alter Column statement that's changing the data type from a Bigint to a Varchar. Immediately afterwards, I need to call Substring() on that column. Unfortunately, the syntax checker of SQL Server won't let me do this. I need to add a 'GO' statement to split the commands. The problem with this is, I also need to i...