sql

Sanitizing a string in Access 2003 SQL: Problem with '

I'm writing a query that has to count the number of students enrolled in a course, and the way I'm doing it is like this: DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'") ...

Help with this SQL query...

The follow query is returning an error at column 143: "ORA-00934: group function is not allowed here" SELECT * FROM TBLENTITYLOCATION TL INNER JOIN TBLENTITY TE ON TE.ENTITYID = TL.ENTITYID WHERE TE.ENTITYNAME = 'foobar' AND LOCATIONDATETIME = MAX(LOCATIONDATETIME) It works fine if I take out the last line - AND LOCATIONDATETIME = ...

Rails questions, SQL statement in logs

So I am new to Rails, so pardon the basic question. I see rails spits this out (in the console) for every request I make to my controller. Why? I'm not even doing any DB operation, I just started writing a HelloWorld rails app. I did pick mysql as the db when creating this rails project (rails -d mysql helloworld) SQL (0.1ms) SET NA...

Creating an ADO.NET Entity from primary key-less view (or stored procedure)

Using either a view and/or stored procedure, I can return the results of executing an MDX query against SQL Analysis Services (using OPENROWSET against a linked SSAS Server into SQL). Unfortunately, the resultset doesn't include a PK field...or for that matter, even a column which COULD act as a PK if I were to hack the model. Can an...

How to find rows where a set of numbers is between two numbers?

I have a query which returns a set of numbers: SELECT Sequence FROM Table1 WHERE Hash=2783342 Returns: 578 642 313 Now, I want to find all rows in the first table where any of that set of numbers is between two other columns. For the purpose of illustration, I am just picking 578, but I also want all of the rest: SELECT * FROM Tab...

How do I use column values as xml element names using for xml in SQL Server 2005?

Simplifying what I'm doing somewhat, as an example, say I have the following tables: declare @elements table (id int, name nvarchar(20)) insert into @elements (id, name) values (1, 'FirstName') insert into @elements (id, name) values (2, 'Surname') insert into @elements (id, name) values (3, 'Address') declare @values table (id int, v...

How to concatenate several create table sentences so the script runs everything with one execute command?

For example, say I have this SQL Script: create table Person ( id int primary key, name nvarchar(40) ) create table Country ( id int primary key, name nvarchar(40) ) How can I have those commands in a single file and be able to run it? ...

Adding a unique constraint on calculated value of a column

Hi all, I'm not exactly sure how to phrase this, but here goes... We have a table structure like the following: Id | Timestamp | Type | Clientid | ..others.. 001 | 1234567890 | TYPE1 | CL1234567 |..... 002 | 1234561890 | TYPE1 | CL1234567 |..... Now for the data given above... I would like to have a const...

myssql foreign key whic is a composite key - what is the syntax?

Is it possible to have a composite key in mysql(5.1) and if so, what is the syntax? table a: column aa,bb references table b columns b_aa,b_bb ...

How can I create a table like this in Microsoft SQL?

Here's what I have so far: create table rubro ( id_rubro int primary key, nombre_rubro nvarchar(150) ) go create table cliente ( id_cliente int primary key, direccion nvarchar(400), telefono int, nit int ) ...

Cannot use GO statement when creating tables in this simple use case.

I'm trying to run this SQL script but it's not working. It says there is an error near the GO text. create table rubro ( id_rubro int primary key, nombre_rubro nvarchar(150) ); GO create table cliente ( id_cliente int primary key, direccion nvarchar(400), telefono int, nit int ); ...

get us, uk in one table, cn and jp in the other, but not br in both

In countrylanguage, countrycode | language US | English BR | Portuguese UK | English in countryname, countrycode | name CN | China BR | Brazil JP | Japan "an inner join produces results by selecting combinations of matching rows from the joined tables. However, it cannot find non-matches" "A left join treats the ...

How do I start to use Version control / Share code in SQL 2005?

I manage a small team of developers who up till recently have all been working on independent projects. We have now all come together to work on one holistic project and its really tough. People are changing things, without consulting other programmers and its very difficult to manage. We are also working in a pure production environme...

Data Cleanup, post conversion from ALLCAPS to Title Case

Converting a database of people and addresses from ALL CAPS to Title Case will create a number of improperly capitalized words/names, some examples follow: MacDonald, PhD, CPA, III Does anyone know of an existing script that will cleanup all the common problem words? Certainly, it will still leave some mistakes behind (less common name...

Sphinx question: Structuring database

Hey, I'm developing a job service that has features like radial search, full-text search, the ability to do full-text search + disable certain job listings (such as un-checking a textbox and no longer returning full-time jobs). The developer who is working on Sphinx wants the database information to all be stored as intergers with a ke...

In SQL Server 2008 how can I query for tables with foreign key references to a specific table column?

In MSSQL 2008 how can I query for tables with foreign key references to a specific table column? Let's say I have a table called Audit with an int column called 'ID". How can I find all the tables in my database that have a foreign key to Audit.ID ? ...

Easy SQL Incorrect Syntax when using > greater than

This has been driving me crazy! It must be something simple. Here is my code: Select logid, row_date, sum(acdcalls) as 'total calls', sum(ti_stafftime) as 'total time staffed', sum(acdtime) as 'time on the phone', Case acdtime When acdtime > 0 Then sum(ti_stafftime/acdtime) Else '0' End as MyPercent, RepLName+', '+RepFName AS Agent, S...

combine SELECTS in ONE VIEW DISPLAY

I need to know of a way to combine multiple SELECT statements in one VIEW? I tried the UNION ALL, but it fails since I am using unique columns to aggregate the GRAND TOTAL. I am a student this is part of a group project. I have one table with 4 columns: account, description, short_description, and balance. The COA (chart of accounts) i...

mysql fulltext is there a way to select relevance as a column?

I would like to know if there is a way I can select the relevance score as a column? So I can store for later manipulation Also is there any way (for trouble shooting) to determine why a row got a relevance? or what words matched. For example when I use WITH QUERY EXPANSION I am getting results and I do not know why they match. ...

Easy SQL Divide By Zero Occurring when Syntax Seems Correct

I am using the following syntax: Case When acdtime != 0 Then sum(CAST(ti_stafftime as DECIMAL)/acdtime)*100 Else '0' End as MyPercent, Yet I am still getting this error: Msg 8134, Level 16, State 1, Line 3 Divide by zero error encountered. What am I doing wrong here? My whole query is below: Select logid, row_date, ...