sql

SQl PAssthrough in SAS

Are there any advantages in using SQL PAssthrough facility along with SAS. ...

DateTime in Calendar Extender

Hi guys, I am using calendarextender control in asp.net.It displays only date ,not time.But while inserting to database ,time is inserted automatically.But while retrieving the data from database using date in where condition ,no correponding records displays.What modification in storedprocedure i can do to resolve this problem. ...

Arithmetic overflow error converting expression to data type datetime.

This select statement gives me the arithmetic error message: SELECT CAST(FLOOR((CAST(LeftDate AS DECIMAL(12,5)))) AS DATETIME), LeftDate FROM Table WHERE LeftDate > '2008-12-31' While this one works: SELECT CAST(FLOOR((CAST(LeftDate AS DECIMAL(12,5)))) AS DATETIME), LeftDate FROM Table WHERE LeftDate < '2008-12-31' Could there be...

Deleting duplicate records using a temporary table

Take the tsql query below: DECLARE @table TABLE(data VARCHAR(20)) INSERT INTO @table VALUES ('not duplicate row') INSERT INTO @table VALUES ('duplicate row') INSERT INTO @table VALUES ('duplicate row') INSERT INTO @table VALUES ('second duplicate row') INSERT INTO @table VALUES ('second duplicate row') SELECT data INT...

Calendar extender

Hi guys, I am using calendarextender control in asp.net.It displays only date ,not time.But while inserting to database ,time is inserted automatically.But while retrieving the data from database using date in where condition ,no correponding records displays.What modification in storedprocedure i can do to resolve this problem. I used ...

Can you use auto-increment in MySql with out it being the primary Key

I am using GUIDs as my primary key for all my other tables, but I have a requirement that needs to have an incrementing number. I tried to create a field in the table with the auto increment but MySql complained that it needed to be the primary key. My application uses MySql 5, nhibernate as the ORM. Possible solutions I have though...

SQL Reporting Services: Grid View

Hi I have designed a query that returns a set of data such as: ============================================ | Name | Phone | Address | -------------------------------------------- Bob - 5 Street Mary - 3 Drive What I want to do in SQL Reporting Services is to display data in a grid fashio...

How to get difference between two rows for a column field?

I have a table like this: rowInt Value 2 23 3 45 17 10 9 0 .... The column rowInt values are integer but not in a sequence with same increament. I can use the following sql to list values by rowInt: SELECT * FROM myTable ORDER BY rowInt; This will list values by rowInt. How can get get the difference of Valu...

How could this be better?

Edit: This application searches in a Sql Server 2000 data base not in a flat file, the flat file only contains the serial numbers that I should look for them in my SQL Server DB table (i.e. the flat file lines will be used as parameters for the where clause only). Hope if it's clearer now! I'm working on .NET windows application that ...

Please help me understand SQL vs C like programming?

Specifically I am trying to grasp how SQL statements differ from normal C style programming, I can't seem to understand how to do stuff like "for every userid in this table that has another column of data equal to such and such, run this stored procedure" which in programming would be a for loop, how the heck do you do stuff like that? ...

Select similar like rows within the same table

I am trying to write a query to find all USERS in a USERS table that are similar. Its like finding all non distinct rows but using a LIKE statement not an equals statement. Below is an example column of a USERS table USERNAME ------------ tim.smith doug.funny tim.smith1 dan.snyder tim.smith20 doug.funny2 emily.hunt after query the o...

Possible to INSERT INTO a table with values from another table?

So say I want to... insert into tableA, 2 variables from tableB, but only rows that are in tableB that have 1 of the variables equal to a certain thing... hmm let's see if I can be more specific... i want to create a new row in tableA with the userid and courseid from tableB for every row of tableB that has a courseid of 11 please ad...

SQL Coalesce in WHERE clause

I'm trying to implement optional parameters in a stored procedure that I have but I am running into a problem. Here's a simplified query to illustrate the issue: SET ANSI_NULLS OFF DECLARE @MiddleName VARCHAR(20); SET @MiddleName = NULL; SELECT * FROM [Customer] WHERE [LastName] = 'Torres' AND [MiddleName] = COALESCE(@MiddleName, [Mid...

SQL Dates Query - how long has this condition been true

The question is how long have these customers been jerks on any given date. I'm working against Sybase For this simplified table structure of table history_data table: history_of_jerkiness processing_date name is_jerk --------------- ----- ------- 20090101 Matt true 20090101 Bob false 20090101 Al...

"One-to-many" modeling question

What is the best way to model the following... Assume I have two objects: Agency and Publisher, and both have a 1-to-n relationship to Employee. This is a true 1-to-n relationship, as each Employee can only work for one Agency or one Publisher. Let's assume further that I cannot introduce a supertype (e.g. Employer) which holds the 1-to...

How to get the Join of Two One to Many associations?

I have two hibernate entities User and Blog. User can be interested in multiple Tags. Blog can belong to multiple Tags. For a User, How do i find the Blogs which belong to the Tags the User is interested in? I need something like Select * from Blog where Blog.Tags IN User.Tags except that SQL or HQL doesnt allow such comparisons in ...

How can I get both the count of a subset as well as the count of the total set in one query?

In the simple case, assume I have a table that looks like this: mysql> describe widget; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(255) | YES | | NULL | | | enabled | smal...

Select newest record matching session_id

I should have paid more attention in relational databases class, so I need some help. I have a table structured like so (there's more, but I'm only posting relevant info): +------------------+-------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------...

How to Properly Convert or Query Date Range for Rails / MySQL DateTime Column

I have a rails application where I store created_at as datetime (standard). I am building a form for searching and I find I have to use find_by_sql to do some complex subqueries. The form has a date range (no time) to search on for items created_at field. The problem I find is that if I pass in just the date string for range to query......

How do I securely delete a row from a database?

For compliance reasons, when I delete a user's personal information from the database in my current project, the relevant rows need to be really, irrecoverably deleted. The database we are using is postgres 8.x, Is there anything I can do, beyond running COMPACT/VACUUM regularly? Thankfully, our backups will be held by others, and the...