sql

Sql: simulate a parametrized LIMIT

Hi, I have a table with SIGNUPS to different events. This table has some simple columns like ID, IDUSER, IDEVENT and DATE. Each event is characterized my a maximum amount of people who can attend, so the table EVENTS has a column called let's say PLACES. What I want to obtain for a given event is the list of the first "PLACES" signups...

Why table exists two times under different aliases in FROM clause of SQL query?

I have this query: SELECT to_number(gr.code) group_index, gr.NAME group_name, f.*, gr.description gr_desc FROM obj$groups gr, obj$group_objects gro, obj$group_objects gro2, tdf$flex_fields f, inv$requests w, inv$Direction_...

The multi-part identifier "Reservation.ReservationID" could not be bound.

I am trying an inner join like this. select R.ReservationID, R.BookingNumber,P.FirstName, P.LastName from Reservation R inner join PersonName P on Reservation.ReservationID = PersonName.ResrvationID I am getting the errors as: Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "Reservation.ReservationID" could not be b...

Optimize query with AVG() and group by on a big table?

I am wondering if there is a way to optimize this query: SELECT Avg(selloff1), YEAR(dt), weekno FROM bbproduct GROUP BY YEAR(dt), weekno Table schema is: CREATE TABLE `bbproduct` ( `id` bigint(20) NOT NULL, `CUSTNO` decimal(6,0) unsigned zerofill NOT NULL default '000000', `DEPTNO` decimal(1,0) uns...

How to Insert Javascript function between sql query ??

Is there any way to insert java-script function between the query ?? For example :: In an query, i have stored date of birth like this 10101990 in the database, it means 10/10/1990, but I have display it in-front of page but in certain format like 10.10.1990 by using one java-script function. Please suggest me any way ?? ...

using SUM and presenting result as absolute (ABS)

I have both positive and negative numbers (money) in a column and need to: SUM the total ie. SUM(myColumn) based on if the numbers are +/- Present the result as an absolute ie. even though the result is -1234 it should be presented as 1234 SQL is not my trade as you probably notice but we've solved most other issues but this one so a...

DB2 - SQL Querie Insert Rows from one DatabaseA.Table to DatabaseB.Table

Hi, is something like this possible in SQL/DB2? INSERT INTO Prod.CD_Final (ID) VALUES (SELECT ID FROM Test.CD_Final); I alway get the error message: "Prod.CD_Final" is an undefined name. SQL Code: -204, SQL State: 42704 "Test.CD_Final" is an undefined name. SQL Code: -204, SQL State: 42704 Thanks, Stefan ...

Money Data Type Precision - SQL Server (SSMS)

In sql server management studio, data type- money, when I enter an amount with a decimal it automatically adds on zeros to fill up to the hundredths. How can I determine the amount of spaces after the decimal? ...

How to Select first 30 chars in a sql query?

SELECT First 20 Chars of(ColName) from DB Is this possible? ...

SQL Database Log file just keeps on growing

Simple Statement of Problem: Log file of a database normally around 80mb expands continually to 10’s of gigabytes with no sign of stopping if I try to initiate log shipping on the database on SQL Server 2005. DBCC SHRINKFILE has no effect. Detailed Statement: I have been implementing log shipping successfully on several databases but ...

Create dll from SQL Server procedure

Hi! I have procedure on SQL Server! Now,is it possible to create dll from that procedure and if it is, how i can do that? Thanks! ...

sql bulk insert with additional column

Hi, A csv file contains 8 columns (col1, col2, ..., col8) and the name of the file contains the date which has to be inserted into the table as well. If the number of columns in the table and columns in the csv file are equal the following query imports all the records from the file to the table: query += "BULK INSERT real_data FROM '...

SQL: Expand 1 Column into 3 on Summarize Table

I'm writing a program that displays products and the stores at which they can be located. So far, I've been able to write an SQL query that displays data as follows: Product Availability Milk Store1 Candy Store1 Eggs Store1 Milk Store2 Eggs Store2 Candy Store3 Eggs Store3 Is there any SQL qu...

How to reuse a dynamic column in another column calculation in MySQL?

I have this kinda query: SELECT IF(daycode=1,(SELECT...),(SELECT...)) AS weekavg, (SELLOFF1 / weekavg) AS procent FROM ..... it tells me: Unknown column 'weekavg' in 'field list', this happens after I've added the divide, prior to that worked ok. ...

C# massive SQL update query

unihere's the scenario: I have a 1.8 million line text file that I need to inject into a SQL table, the code i have works fine, just kind of slow (like 250k lines per day). Unfortunetly I have about 4 text files this size to go threw, so I need a way to speed up the process. Any help would be appreciated. if some of the code doesn't ...

SQL Server 2008 compatibility level

After migrating a database from SQL Server 2000 to 2008, in what situations is it justified to leave compatibility level to 80 permanently. The system consists of stored procs, triggers, views and tables only. No DTS, reports and other non-database engine stuff. ...

CPU Pinned above 95% when BDC profile import (Full and Incremental)

We have daily full profile imports using BDC connection. In that duration, CPU spiking very high. That team is concern. How to resolve this issue. Please anybody have any idea on this? Please share with me. It is physical box with 16 GB RAM. CPU is spiking all the way till its complete BDC job (not like only initially). I have 85000 rec...

Stored procedure with FAST_FORWARD cursor loop starts fast, ends slow

I have a stored procedure that uses a FAST_FORWARD cursor to chronologically loop over a set of ~300k records and assigns them to declaration sets based on the state of a lot of running variables and flags, partly implemented as table variables. I have given a lot of thought on how to do this set-based and I just can't do it. So I am stu...

sql server 2000 using hint in view

CREATE VIEW xxxx AS SELECT order_date, DATEPART(W, order_date) AS dayID, Type FROM dbo.Shipment_Dates WHERE (TIP = 'normal') OPTION (FAST 20) This create statment causes error at hint part .. Is there a workaround for adding hint to views? ...

Postgres case statment

Hey everyone, I am currently working with some of my teacher's old Postgres SQL code and modifying it to match what I need. However, there is one piece of code that I can't seem to find an explanation of anywhere online. In the code he had a case statement with a ~~* used as what looked like a comparison. I am unfamiliar with this synta...