sql

how to approach this specific query

Hi, I have a rather complex logical query I'm trying to execute. Essentially there are a series of related tables. I am having difficulty figuring out a good way to approach it. Tables: Transaction - T_id Discount - D_id item_id Type (percentage or basic value) value Transaction_Discount - T_id D_id Item - item_id price ED...

NHibernate - Lazy-Loading primitive type

I'm using NHibernate to load some objects into my ASP.NET MVC application. For example, a submission is submitted by a user, and I want to display the username (but only the username) of a user, like this: <%= Html.Encode(item.User.UserName) %> When I load a submission using NHibernate, the User is lazy-loaded from the database, whic...

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

MySQL problem: Merging multiple results/rows caused by n-m

Hi everybody, i tried now nearly everything i could to solve he following problem. So far with no success. But there must be a solution cause i dont think the case is s.th too special. I think i am just a bloody beginner ;-) I need to join union merge or whatever ;-) in MySQL to solve the following problem... CASE: Three tables "posts"...

getting USERID problem from accessdatabase.

hello everyone. i am lilly, i have a problem. i have a window in wpf. when user enter name, i wanna insert it to database and get USERID. but i cant success it. if you help me, i will be so happy. thanks in advance. private void button1_Click(object sender, RoutedEventArgs e) { OleDbDataReader rd; strin...

What permissions for PHP scripts/directories?

Hi, I am trying to help a friend moving a web-site from one web-hotel to another. The old place is already closed, I have only a flat tar file of what was in it. I apologise if this is a basic question. I am new to this... The web site contained html docs and one could download a little java application (to be loaded on mobile phone) ...

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

SQL query from flat file

I have a table such as: John email1 email2 email3 ...and so on I need to transform the dataset to this format: John email1 John email2 John email3 it could be exported out to Excel and the imported back in if that would be easier. Thanks... ...

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

Matching Two Large Sets of Strings in C#

Here is the situation: I have a webpage that I have scraped as a string. I have several fields in a MSSQL database. For example, car model, it has an ID and a Name, such as Mustang or Civic. It is pre-filled with most models of car. I want to find any match for any row in my models table. So if I have Civic, Mustang and E350 in my ...

Rails way to reset seed on id field

I have found the "pure SQL" answers to this question. Is there a way, in Rails, to reset the id field for a specific table? Why do I want to do this? Because I have tables with constantly moving data - rarely more than 100 rows, but always different. It is up to 25k now, and there's just no point in that. I intend on using a scheduler in...

Why does my CLR function keep disappearing

Hi there. I am a rookie to SQL and here is my questions. I have some CLR sql functions and procedures. When I deploy the 1st one, everything is fine. But after the 2nd one deployed, the first one will disappear. Anyone can help me out? Thanks a lot Actually, I simply create a new SQL project in VS, adding a new function or stored ...

Query direction issue

Hi, I am stuck at the start of a small project and I am not sure what would be the best way to go with a query etc. The story is that I have a table with members predictions on a particular sport. They have predicted the top 5 places of each event (about 19 events in total). Some of these predictions have been entered more than once as...

What are ways to match street addresses in SQL Server?

We have a column for street addresses: 123 Maple Rd. 321 1st Ave. etc... Is there any way to match these addresses to a given input? The input would be a street address, but it might not be in the same format. For example: 123 Maple Road 321 1st Avenue Our first thought is to strip the input of all street terms (rd, s...

Creating and looping through a list in an sql server stored procedure

Is there a way to declare a list of items in an sql server stored procedure using T-SQL and then loop through the items? I'm trying to do something like this: input_string = 'my dog has fleas.' list_remove = 'a', 'e', 'i', 'o', 'u' for each item in list remove input_string = replace(input_string, item, '') end And in the end inp...

Has anyone implemented the chain ladder method via SQL ?

Hello All, Has anyone implemented the chain ladder method via SQL ? It's a method used in actuarial science. ...

how to safely generate a SQL LIKE statement using python db-api

I am trying to assemble the following SQL statement using python's db-api: SELECT x FROM myTable WHERE x LIKE 'BEGINNING_OF_STRING%'; where BEGINNING_OF_STRING should be a python var to be safely filled in through the DB-API. I tried beginningOfString = 'abc' cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%', beginningOfStrin...

Fetch the row which has the Max value for a column in SQL Server

I found a question that was very similar to this one, but using features that seem exclusive to Oracle. I'm looking to do this in SQL Server. I have a table like this: MyTable -------------------- MyTableID INT PK UserID INT Counter INT Each user can have multiple rows, with different values for Counter in each row. I need t...