sql

Clean up CREATE TABLE column layout

I've got a series of sql scripts that look like this: CREATE TABLE table_one ( column_one int not null, column_two varchar(100) not null, column_three_four_five int, column_six decimal(16,4) null, PRIMARY KEY ( column_one, column_three_four_five) ); I'd like to clean up the layout t...

Pagination Class calculates incorrectly.

hi, ive written a pagination class and it looks like its not outputting the correct amount of rows. i have a table full of 51 records and instead it shows only 30 records and as for the pages it shows only page 1 where it should show page 1 and 2. the pages are viewed by going to page=1 as a browser param. when i try to view page=2 i see...

SQL - How to join top ordered results from pictures table with product table ?

I have a products table, and a pictures table as such: Products id name model Pictures id pid url order The picture for each pid with the highest order is the cover picture. There can be more than 1 picture per product. I want to join this result when I query the products, so it would show these r...

Trouble with GROUP BY CASE

The following query gives the error "#1241 - Operand should contain 1 column(s)" because of the (Department_Code, Course_Code) line. When I replace that with just (Course_Code) it works. However, that's not what I want SELECT * FROM Classes GROUP BY CASE WHEN (1) THEN Department_Code ELSE CASE WHEN (2) THEN (Department_Code, Cou...

[ADO] Why can't I get the recordset directly from the stored procedure?

I have a SP as follows. When I execute it with ADO, the first returned recordset is closed. I have to call the NextRecordset method to get the recordset I want. Why is that? How can I avoid the trouble? Thank you. create proc GetTeamCurrentPlan @ReleaseID varchar(30) as set nocount on declare @CurrentSp smallint set @CurrentSp=...

how to retrive the values for textarea from db in asp

if anyone knows plz reply ...

Why the LEFT OUTER JOIN performace is bad on SQL Server CE 3.5?

hi i tried a select query that contains an left outer join on SQL Server CE and its taking like 30 seconds to execute. and then i changed the same query to be an inner join and its taking less then 1 second. the same outer query is very fast on SQL server 2008. does anyone knows why is that? also what is the fix for this performance pro...

SQL Server SQL Select: How do I select rows where sum of a column is within a specified multiple?

I have a process that needs to select rows from a Table (queued items) each row has a quantity column and I need to select rows where the quantities add to a specific multiple. The mulitple is the order of between around 4, 8, 10 (but could in theory be any multiple. (odd or even) Any suggestions on how to select rows where the sum of a...

GROUP BY with MAX(DATE)

Hello everyone, I have a table showing trains with their destination and departure time. My objective is to list the latest destination (MAX departure time) for each trains. So for example the table is Train Dest Time 1 HK 10:00 1 SH 12:00 1 SZ 14:00 2 HK 13:00 2 S...

Execute Query depending upon select query value.

How to achieve the following query - SELECT CASE WHEN COUNT(*) > 0 THEN -- UPDATE operation ELSE -- INSERT operation END AS [RESULT] FROM [TABLE_1] WHERE [CONDITION] I am using SQL Server 2000. Can someone please help me? ...

date ranges in where clause of index view

I have an index view which I run a query against with WHERE GETDATE() BETWEEN start_date AND end_date in the WHERE clause. I suspect that the answer to my question is probably going to be no, but, is it possible to push this into the index view or do something clever to achieve the same effect? My concern is that what the index vi...

INSERT from SAS 9.2 to SQL Server 2005 fails when table has a trigger

I connect to an SQL Server 2005 DB from SAS 9.2 via SAS/Access ODBC Driver. In the DB, I have a table my_table, which has an INSERT-trigger that copies all the inserted rows into another table in the database. In the SQL Server environment, the trigger works normally. However, SAS Proc SQL doesn't seem to get on well with a table with t...

Nested Callback Handlers?

I am getting a set of data from the database where the query produces a repetition of data with a different "Special" value. For example the user "A" can be repeated twice, having three different "Special" values under the "Special Column". I am using a callback handler to retrieve the data and put it into a list, now additionally I wan...

Newly Created Function Is Not Available?

I am working on a scalar value function in MSSQL 2008. I created it and It is shown in object Explorer But when I use this function in MS Query Analyzer It gave me error **Msg 208, Level 16, State 3, Line 1 Invalid object name 'calculatecptcodeprice'.** For Me this type of error after creating Function is new. What went wrong. Please ...

consitent vs peformance database design for db polymorphism with versioning

I need to create a database for 2 types of farmers (organizations and landlords) which have different columns that need to be stored and I also need to version their info. One db design that I came up with is this: (the consistent one) Farmers Id FType check(FType in ('organization', 'landlord')) Unique(Id,Ftype) Organizations Id ...

Problem with SQL query

Hi. I have two tables test1 { id, name } and test2 { id, name, family } and i write this query: SELECT dbo.test1.*, dbo.test2.* FROM dbo.test1 CROSS JOIN dbo.test2 but in datagridview1, I want to show the fields (on header) like this: test1.id test1.name test2.id test2.name test2.family, except this id name id nam...

How to send an email?

hi, i have an datatable like this. i have an excel sheet like this. now i am reading the data from that and converting into an datatable like this id Name MailID Body 123 kirna [email protected] happy birthday 234 ram [email protected] happy birthday 345 anu [email protected] how...

LINQ to Entities - Where IN clause in query

Possible Duplicates: Linq to Entities - Sql IN clause How to implement SQL in in Entity framework 4.0 how can I add WHERE IN statement like... SELECT * FROM myTable WHERE ID IN (1,2,3,4,5) in entity framework ...

Dynamic dependency view SQL and SSIS packages

Hi All, In my enterprise project we have nearly 800 tables with 7 staging areas. We have developed nearly 100 packages to implement the DW. Business users constantly chaging the requirements after completing all the packages like table/column names, PK/FK columns with many other changes due to business requirements. Being changes in t...

SQL Server and Oracle read / write roles

Hi, I need to create some roles (I don't know how to call it correctly, so I'll name it 'role :)) on SQL Server and Oracle, and I really don't know much about both DB servers, so I don't know what I should look for. I need to create 2 roles: users who can only filter data from tables (SELECT). users who can modify data (i.e. DELETE st...