sql

Create View SQL

I am a student this is homework. I use SQL server to check my work but have to write script by hand. Create and display a VIEW that displays the account balance subtotals for each account group. Account group is defined as the first two digits of the account number. Display a grand total of the balance column at the end ...

distinct on a single column, yet returning a row from the same table based on an unselected condition

I am new to Sql server, and my MySql background is only decent, nothing exceptional. I have a table with 5 columns: Neighbrhood City State zip_code zip_percent The goal of the query: To provide a list of neighborhoods (unique) within a city and the zip_code that corresponds with the highest zip_percent. Thus returning 2 columns: Nei...

Simple Foreign key / Create View question

What am I doing wrong? I need to create the foreign key but the code begining at CONSTRAINT is wrong somehow, also I need help with my view I think im doing the subquery wrong can you help me? CREATE TABLE dealer( dealershipId CHAR(10), phone CHAR(10), dealershipName CHAR(10), webAddress char (10), street CHAR (10), city char (10), zip ...

Get list of tables but not include system tables (SQL Server 2K)?

Hey all, I know I can get a list of tables from a given database with the following query: select * from information_schema.tables How do I go about excluding system tables though? Thanks, Sonny ...

What is passing parameters to SQL and why do I need it?

Beginner here: In this answer to my question of how to insert data into SQL Server he mentioned passing parameters instead of string concatenation like I currently have. Is this really necessary for security? If so, what exactly is passing parameters? When i google it I get a lot about stored procedures. Is that what I want, I do n...

Compute median of column in SQL common table expression

In MSSQL2008, I am trying to compute the median of a column of numbers from a common table expression using the classic median query as follows: WITH cte AS ( SELECT number FROM table ) SELECT cte.*, (SELECT (SELECT ( (SELECT TOP 1 cte.number FROM (SELECT TOP 50 PERCENT cte.number FROM cte ...

Custom Sort Order - How to not duplicate the Case statement

I have the following Db and query. The query takes two parameters: the sort column and the direction. However, I have to add custom sorting to the query (based on the Fuji should come first and Gala second, etc.). This part also work but it create duplicated code in my query. Because of that, I am pretty sure people will not let me check...

Folder permissions based on users and groups

Hey Im working on a folder tree and need to be able to limit the visibility of certain folder based on the user and the group they belong to. I already have a database representation of all the folders in the tree and the hierarchy of the folders. My question now is how to best represent the permissions. If I have to possibly look up p...

mysql query - select distinct value where it has a specific values , group by

I currently have SELECT * FROM bidders WHERE status='0' AND email IS NOT NULL GROUP BY `bid_user` ORDER BY 'bid_price' DESC The problem that I have is that "bid_user" may exist in different rows with different status ( status=1 or status=0). I would like to know if it's possible to select only the * rows where status=0 and whe...

How to "Import" a *.SQL File

I am hosted on Winhost.com. They support both PHP and ASP.NET. I have a PHP User Management script and the instructions are as follows: Step 1 : Login to your web hosting account and create a database and inport the database.sql file. Step 2: Open config.php with notepad and change the settings to your database details. Step 3: Upload...

SQL Server Select query optimization

Hi, I am looking at some feature which will enable me to partition tables horizontally, i.e. the context of me referring to a table is only a sub-set of the entire set of records in a table. This could be a typical scenario in a SaaS model since data of one account is not of significance to another. Let us say, there is a...

shared stored procedure

Let's say I have many sql server databases which have exactly the same schema. Is there any place where I can write a stored procedure and apply for all databases? If I create the stored procedure for each database, when needed, I have to update them all. ...

MySQL query error.

Can someone help me correct the following error I keep getting when trying to run my MySQL query. Here is my error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id = '3' AND id = '3' AND friendship_status = '0'' at line 2 Here is my m...

error while uploading a large excel file data into SQL server from ASP interface

Microsoft OLE DB Provider for ODBC Drivers error '80040e31' [Microsoft][ODBC SQL Server Driver]Timeout expired ...

MySql sever instance configuration wizard help

I have uninstalled mysql from my system long ago and i have forgot the passowrd i have set to mysql now when i tried to install it its asking for the old password to set the new password in MySql sever instance configuration wizard i am not getting access to mysql command line client. ...

Separate value form field to row SQL Server 2000

So,please help me to split value from table like below field A has value below 13974;14098;14237;14269;14317;14319;14392;14393;13 257;13983;13820 and i need to split and down value in row like below file B 13974 14098 14237 14269 .... please help me to supports many thanks ...

execute sql which is placed in an xml file using Java code

how to execute sql which is placed in an xml file using Java code? ...

Need help writing a SQL query

Im an SQL noob. Heres my situation. I have the following tables. Customer_table Customer_ID | Last name | First Name | City_ID | Region_ID | Country_ID Country_table Country_ID | Country Region_table Region_ID | Region | Country_ID City_table City_ID | City | Region_ID | Country_ID I need to find the number of cus...

SQL Server OFFSET equivalent

Hello everyone, I am using SQL Server 2008 Enterprise on Windows Server 2008. I want to select result from top 11 to top 20 (e.g. I am only interested in the 11th to the 20th result). Any ideas how to write this query in tsql efficiently? thanks in advance, George ...

What is "query writer, new querry in sql server management studio express

using :- sql servr 05 and vs08 c# website asp.net Okay, I have always used SQL Server 2005 Express and its Management Studio as a host and a design interface to create tables from design view only. All the queries, transaction, retrieval and anything needed during run time of the website is done using Visual Studio 2008 sql "connection ...