sql

Select DISTINCT, return entire row

I have a table with 10 columns. I want to return all rows for which Col006 is distinct, but return all columns... How can I do this? if column 6 appears like this: | Column 6 | | item1 | | item1 | | item2 | | item1 | I want to return two rows, one of the records with item1 and the other with item2, along with all oth...

must declare the scalar variable (sql server 2005).what is this error?

SELECT * FROM [tbl_students] WHERE course_id=@courseId AND branch_id IN(646768) AND (@firstYrPercent is null OR first_year_percent>=@firstYrPercent) AND (@secondYrpercent is null OR second_year_percent>=@secondYrPercent) AND (@thirdYrPe...

query to join two tables using a primary key and comma separate the results

Hi, Suppose there are two tables- T1 T2 --- ---------- A A | 1 A A | 2 A A | 3 How to write a query that returns the results as following Col1 Col2 ---- ----- A 1,2,3 (One row) Thanks in advance ...

SysIndex - difference b/w is_unique and is_unique_constraint

runing a select query on SQL Server 2008, sys.indexes gives me information on the index define for a database . There 2 fields is_unique and is_unique_constraint. I dont understand the difference b/w them . ...

SQL SERVER CASE STATEMENT CLARIFICATION

I have to execute a statement like ( i need and keyword along with when ). select 'Is Allowed'= case A.Column when A.Column='XXXX' and Isnull(A.AnotherColumn,'')<>'' then 'Yes' else 'No' end from TableName I am getting syntax error,how to rewrit...

get ssis package output from SP

I have a SP that runs a SSIS package. xp_cmdshell 'dtexec /f "F:\SSIS Package\test.dtsx" /Rep E' When I run the SP in VS I get an Output window where I can see if it was successful. Is there a way to get the output from this into my asp.net application ? ...

To create a SQL script for generating table schema with data for a DB2 table

HI, Is it possible to generate SQL Script to create table schema along with the data currently present in the table. Thanks ...

Django-like data model in ASP.NET MVC

Is there anything similar to Django data models in ASP.NET MVC where I can easily manipulate my classes and objects and don't worry about SQL realization of it? ...

How to calculate maximum of two numbers in SQL select

This should be simple and shows my SQL ignorance: SQL> select max(1,2) from dual; select max(1,2) from dual * ERROR at line 1: ORA-00909: invalid number of arguments I know max is normally used for aggregates. What can I use here? In reality I want to use somthing like select total/max(1,number_of_items) from xxx; where nu...

MS Access: setting table column Caption or Description in DDL?

Is it possible to set a table column's Caption or Description properties in MS Access using DDL? Ideally, we could include them in a CREATE TABLE statement. ...

"Object reference not set to an instance of an object." in C#, SQL 2005, VS 2008

I am trying to select "food_ItemName" and "food_UnitPrice" from "t_Food" table in SQL Server 2005. I have the following code: private void GetDatabaseConnection() { string connectionString = @"Server = RZS-F839AD139AA\SQLEXPRESS; Integrated Security = SSPI; Database = HotelCustomerManagementDatabase"; connection = new SqlConnec...

Wordpress SQL query: get random child page

I want my site to have a random "welcome" page. I've found a plugin that redirects to a random page. I want to specify a parent page that random child pages are selected from. This is the query that the plug-in uses: $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_password = '' AND post_status = 'publish' ORDE...

Relational database backend for mercurial or git

What I like about fossil is that it uses plain old sqlite to store changesets, files, etc. I can use its command line tool to query the repository, but if I want something not supported by it, I can fallback to writing an sql query. Mercurial and git are more mature, they have more libraries, more momentum, but they use their own reposi...

SQL Server View Primary Key

Is there a way to give a view a primary key in sql server. I know it is possible in oracle. I am not concerned about updates its a read only view but someone else is using it in ms access so I would like the constraint that I know to be correct to be shown. ...

should I use LIKE to query tables with 4 million rows

I am designing a search form, and I am wondering whether should I give the possibility to search by using LIKE %search_string% for a table that is going to have up to 4 million rows ...

simple sql query, combine results and divide

Hi all. I'm trying to get 2 counts from 2 tables and work out the percentage like for a mysql db 1) select field_one, count(*) as COUNT_ONE from table1 group by field_one; 2) select other_field,count(*) as COUNT_TWO from table2 group by other_field; I want to combine the results and have FINAL_COUNT=(COUNT_ONE/COUNT_TWO) * 100 for pe...

Get index of row within a group?

Hello! I have two tables: Unit: UnitId int PK Title varchar UnitOption: UnitOptionId int PK UnitId int FK Title varchar Quote: QuoteId int PK UnitOptionId int FK Title varchar I want to create a scalar UDF that takes a QuoteId param and returns a varchar that contains the following description (pseudu): Quote.Title + '-' + Unit.Ti...

How to Convert these3 SQL queries into One ?

Is there anyway i can convert the below 3 sql queries into a single query ? insert into table1(Name,Age,Type) Select FirstName,Age,'Type1' FROM Table2 where Type='SK' insert into table1(Name,Age,Type) Select FirstName,Age,'Type23' FROM Table2 where Type='JK' insert into table1(Name,Age,Type) Select FirstName,45,'Type64' FROM Table2 wher...

How to get execution time in rails console?

I want compare time of execution Post.all and SELECT * FROM posts (or some other statements) How can i get execution time of Post.all ? ...

Unused Database Table Effects

In our SQL Server Database we have at least 25-35 lookup / empty tables that are never used. Is there any negative effect for keeping them in our database (performance, storage etc) Basically, would deleteing them have any positive impact on queries etc. ...