sql

Join to table-valued function in MSSQL 2000?

I have a table with a whole name. I have a function that receives said name, parses it, and returns a table with first, middle, last, and suffix. I have a bad (edit: was "hyper-conservative") DBA who won't upgrade the dev server to the same version as the production one so I can't just use APPLY and be done with it: insert into blah (...

SQL Help in Access – Looking for the Absence of Data

I am trying to find the fastest way to find all of the records in a parent table that do not have certain records in a child table. For example, I want the query to return all of the family records where there are no male children or no children at all. Example 1 This is painfully slow: SELECT * FROM Families WHERE Families.FamilyID ...

What is the best way to query data from multilpe tables and databases?

I have 5 databases which represent different regions of the country. In each database, there are a few hundred tables, each with 10,000-2,000,000 transaction records. Each table is a representation of a customer in the respective region. Each of these tables has the same schema. I want to query all tables as if they were one table. The...

Round in MS SQL on 0.05 or 0.00

Hello I am coming from Bosnia and Herzegovina and in our county the smallest note bill is 0.05, Now the government pushing us to our retrial prices rounding on 0.05 or at 0.00. Therefor I want to create SQL Scalar Valued Function for rounding the prices on given value. Is there some build in solution so I can save resource of my querie...

How could I rewrite a query without using joins

I would like to know how this query would be written if no joins were used. I been trying to figure it out for cases where joins aren't viable or can't be used(aren't available). SELECT * FROM ( table1 INNER JOIN table2 ON table1.id = table2.id ) INNER JOIN table3 ON ( table1.id2 = table3.id2 ) AND ( table1....

How to invert words in a column

I have a table with varchar(128) column with data like: word1, word2, , word3, word4 word1, word2, word3, , word1,,,, ; word2 ;word1 word2, word3 I have to update this table, making words reverse order: word4, ,word3,,word2 ,word1 ,,word3, ,word2, word1 Could you help me to do it using only single sql query?? ...

Progress Bar for calls to SQL from .Net

I'm wondering if there is a tried/true method for reporting the progress of a DB call from a .Net application to its user. I'm wondering if it's even possible to actually indicate a percentage of completion, or is the best/only approach to simply display a "loading" animation to indicate that something is happening? Also, does SQL2008...

Linq To SQL and Having

I am fairly new to Linq To SQL but trying to run what should be a fairly simple SQL query and can't figure out how to make it play nice in LINQ. SELECT Users.Id, Users.Id AS Expr1, Users.FirstName, Users.LastName, User_x_Territory.UserID FROM Users LEFT OUTER JOIN User_x_Territory ON User_x_Territory.UserID = U...

How can I execute a UDF on multiple rows?

I have a user defined function defined in SQL Server. I want create a single select statement that would be able to execute the function on all rows in a particular column. Is this possible and what would be the best way to do it? Thank You I saw this 'Execute table-valued function on multiple rows' and dont believe it answers my que...

SQL error with script to create

I used the SQL Server management studio on a table with Create Script to New and did minor changes. Give me an error "Incorrect syntax near '('" for the "(" after "WITH" /* EventType Table Creation */ CREATE TABLE [EventType] ( [pkEventID] [int] IDENTITY(1,1) NOT NULL, [Description] [nvarchar](50) NOT NULL, [BeginDate] [datetime]...

Using While Loop for SQL Server Update

I am trying to become more efficient in my SQL programming. I am trying to run a loop to repeat an update command on field names that only change by a numerical suffix. For example, instead of writing out x_1, y_1, then x_2, y_2 for each update: DECLARE @a INT DECLARE @b VARCHAR SET @a = 1 WHILE @a < 30 set @b = @a BEGIN UP...

L2Entities, stored procedure and mapping

Finally checked out L2E framework and ran into problems almost instantly. Yeah, i know... i should read some books before. Situation: entity with props -> id and name. entity is mapped to table, which has id and name columns. sproc, which returns ONLY id column. Problem: ObjectResult<MyProp> result = _container.MyStoredProced...

SQL Server 2000 blocking problem solved by running profiler?

We are working on a large Java program that was converted from a Forte application. During the day we are getting Blocking SPID's in the server. We had a DBA visit yesterday and he set up a profile template to run to catch the locking/blocking action. When we run this profile the blocking problem goes away. Why? This application is dist...

Conditional prepared statement not switching

I have the following PHP code, which is meant to insert data in the event that the username field is empty for a given username, or update data if a username exists. At the moment, the insert was previously working fine, but it would never switch to the update clause. Now however, the insert clause fails to recognise my test variable, f...

Best way to test SQL queries.

So i have run into a problem in that we keep having complex SQL queries go out with errors. essentially this results in sending mail to the incorrect customers and other 'problems' like that. What is everyone's experience with creating SQL queries like that, essentially we are creating new cohorts of data every other week. so here ar...

Finding and displaying duplicates

I have a table. I'd like to search within this table for duplicate titles. Lets say my data is as follows: title1, title2, title3, title1, title4, title2, title9 I'd like for my query to search this table and output only the duplicates. So the output would look like: title1 title1 title2 title2 I know how I can find the duplic...

SQL Bulk Insert error 4863

Hey guys, I am trying to import some data to SQL Server 2008 by means of Bulk Insert, but I've been getting a ton of conversion errors: Msg 4864, Level 16, State 1, Line 1 Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 5902, column 2 (Type). OK so first things first: a) the da...

sql limiting for unique records

I have a table that may have about 100 records or so, with a user name field. There may be many records with the same username. How would I ensure that only one record for each username is returned, regardless of which record it is? e.g. for the following table users username item firstname lastname -------------------------------...

sql - updating without overriding existing information

I have the following conditional code, which will insert a new record if a record with the appropriate username does not exist, and update the record if it does exist. This works fine. However, at the moment, if I insert a new record, and only insert the firstname and lastname, and maybe address details with say phone information being ...

how to get random data from database?

I have a table of product. I have listed the items with pagination using rand() function. When using rand(), it displays the items in random order but the record is repeated while we go from 1 page to another page. Is it possible to get non repeated items in each page using rand()? If yes how, if no what may be the option for this. ...