sql

I cannot calculate a division in my SQL code

The following code works without problems: select donem, mekankodu, count(yayin_kodu) yc, SUM(CASE WHEN iade =0 THEN 1 ELSE 0 END) yys from ( select donem, bayi_adi, bayi_kodu, x.mekankodu, mekan_adi, mekan_tipi, yayin_kodu, yayin_adi, ...

Perform this query when something doesn't exist in another table.

Hello, This is a really tricky question to ask as its very hard to explain what I'm after. Here goes though! SELECT Stock.*, REPLACE (Description, '&', '&') as Description, PRD1.RuleValue AS Price, PRD2.RuleValue AS WasPrice, PRD2.RuleValue-PRD1.RuleValue AS Save FROM Stock INNER JOIN StockCategoryMem...

SQL Query JOIN Performance

Hey all, I wanted to know what is better performance-wise: to put the conditions in the JOIN? (x JOIN y on x.hi = y.hi AND ....) or maybe to put it under the WHERE, and leave the JOIN only with the crossing condition. thanks folks ...

Optimizing suggestions needed for a SQL UPDATE statment. Two ~5 million record tables being used.

Hello, I'm looking for any suggestions to optimize the following PROC SQL statement from a SAS program. The two tables involved contain around 5 million records each and the runtime is about 46 hours. The statement is looking to update a "new" version of the "old" table. Noting a column if the "old" table, for a "PK_ID", was listed ...

Is Lazy Loading really bad?

I hear a lot about performance problems about lazy loading, no matter if at NHibernate, Linq.... The problem is N+1 selects. Example, I want all posts and its users, at foreach I lazy Load Users, them I need one select for posts, plus N select for each user. Lazy Loading: 1 - select ....from post N - select ....from user The "good" ap...

A simple but challenging SQL Question, at least I couldn't find a way out except doing it externally (c#).

Hello All, I have an SQL Table which consists of 1 column only Column Name A A A B B B B C D D E I need an SQL Code that returns the cut points. For the table above, it will return this: Column Name 3 7 8 10 11 3 is the end of A's and 7 is the end of B's and 8 is the end of C's and so on... Let's see what can...

Multiple and single indexes

I'm kinda ashamed of asking this since I've been working with MySQL for years, but oh well. I have a table with two fields, a and b. I will be running the following queries on it: SELECT * FROM ... WHERE A = 1; SELECT * FROM ... WHERE B = 1; SELECT * FROM ... WHERE A = 1 AND B = 1; From the performance point of view, is at least one...

How to make a nested query?

Have a table users and there is a field invited_by_id showing user id of the person who invited this user. Need to make a MySQL query returning rows with all the fields from users plus a invites_count field showing how many people were invited by each user. Something like this: SELECT User.*, Count.count FROM users AS User, ...

SQL 2005 Full-Text-Search: How to default all user search words to a CONTAINS NEAR type FTS search.

I have an asp.net web page with a simple search text box that returns matching rows from a MSSQL 2005 database. It is currently using a LIKE statement to bring back matches, but forces the user to to type an exact phrase. Users want a more Google search type experience and so I have decided to set up and index the needed tables with FTS....

SCOPE_IDENTITY is not working in asp.net?

I am trying to insert a record and get its newly generated id by executing two queries one by one, but don't know why its giving me the following error. Object cannot be cast from DBNull to other types My code is as below: (I don't want to use sql stored procedures) SqlParameter sqlParam; int lastInsertedVideoId = 0; using (...

SQL Server Reporting Services 2005 - How can I get the report to scale to one page wide when printing?

I have a report and it seems so insist on printing in portrait mode and splitting the report across two pages. How can I make the web version specify landscape automatically, and also have it scale to fit on one page? ...

Cannot see table in Object Explorer, SQL Server 2005/2008

This may be a dumb question. But I just received permissions to read/write to this DB. I see the tables of the DB, except for one. I can select from it, But I cannot see it in the Object Explorer. I restarted my computer, refreshed the object explorer and everything. Is there a restriction on viewing this table? ...

Generic Database Code Table Editor

Where can I find a generic editor (JSP using Oracle's ADF) for create, read, update, and delete on any table? Example usage: User selects the name of a table. User then adds a new row, or updates/deletes an existing row. User saves the changes. Foreign keys would appear as drop-down lists, and all others as af:inputText. (The user-f...

Joining SQL result with string

Hi, I have a MSSQL 2005 database with a lot of records that were added since last backup. I want to make another SQL script that puts result values into string representing INSERT statement that I will save for later use. Something like: SELECT 'Insert INTO tabname columns VALUES("+Column1"',')' FROM XY Or simple example: Column A,...

Reporting Services: Creating user defined functions in report query. Is it real?

Is it possible to create and use a user defined function in a report query? Something like this: if OBJECT_ID('userFunc', 'TF') is not null drop function userFunc go create function userFunc(@id int) returns @tbl table ([id] int) begin insert into @tbl (id) values(@id) return end go select * from userFunc(1) if OBJECT_ID('userFunc',...

generate days from date range

I would like to run a query like select ... as days where `date` is between '2010-01-20' and '2010-01-24' And return data like: days ---------- 2010-01-20 2010-01-21 2010-01-22 2010-01-23 2010-01-24 ...

ColdFusion: How to insert numbers( having a 'comma'(,)/ currently iserted as 0) from form fields into the database.

A form field value like 45,234 is to be inserted into the DB as 45234. When I try to do insert for 45,234, all it gets into the DB is 0.Note:- I am able to insert 45.234as 45.234 in the SQL DB. The form field is named costOfShares, which is to be inserted into the table ShareVales (SQL Server 2005). I am using CF8. SQL table:-ShareVa...

Why doesn't STDifference between a LINESTRING and a POINT on the line string yield a MULTILINESTRING of the two pieces?

DECLARE @Route geography SET @Route = geography::STLineFromText('LINESTRING(-0.175 51.0, -0.175 59.0)',4326) DECLARE @Route2 geography SET @Route2 = @Route.STDifference(geography::STPointFromText('POINT(-0.175 52)', 4326)) SELECT @Route2 Why does @Route2 evaluate to LINESTRING (-0.175 59, -0.175 51) instead of a MULTILINESTRING consi...

recieving only the structure of the table using SQL and PHP and put into an Array

Is it possible to recieve only the structure of the table even if its emtpy and put the field names in an array. if so wich sql command makes that possible. thanks Matthy ...

SQL Server 2005 query multiple Access databases?

Is there a way to get SQL Server 2005 to query 3 or more separate Access databases (each returning 1 record) in one SQL statement? ...