Data Access :: How To Get Min Of More Than One Column In Select Query

Nov 24, 2015

I am using SQL select query to select MIN from column data but I have 12 columns and want to select MIN of all these 6 columns in one SQL select statement.

I have written as SELECT MIN(temp_sv,humidity_sv,SH1,SH2,SH3,SH4) from production but its not working... How to do this....

View 4 Replies


ADVERTISEMENT

Select Query As Column Data

Aug 8, 2013

Outer query: select op.const_cd, (select const_hin from constituency c where c.const_cd=op.const_cd) from PollingStation op, constituency c

where op.const_cd=c.const_cd

group by op.const_cd
order by op.const_cd

Result is:
122 a 205
123 b 205
124 c 235
125 d 191
126 e 226
127 f 159
128 g 165
129 h 175
130 i 225
131 j 213

Inner Query result of: select const_cd, count(polling_cd) from PollingStation p where right(polling_cd,1)='A' group by p.const_cd order by p.const_cd:

122 4
123 4
124 2
125 3
126 1
127 6
128 11
129 9
130 2

I want this output:

const_cd const_name count inner query
122 a 205 4
123 b 205 4
124 c 235 2
125 d 191 3
126 e 226 1
127 f 159 6
128 g 165 11
129 h 175 9
130 i 225 2
131 j 213

View 8 Replies View Related

How To Write Query To Select Second Row Column Data

Nov 18, 2013

I have a requirement like below .

Input table will be like below:

eventdata:
accountID deviceID timestamp speedKPH address
--------- -------- ---------- -------- -------------
preva1 bolero 1359089006 15 Ullalu Road
preva1 bolero 1359088796 0 Ullalu Road
preva1 bolero 1359088886 0 Ullalu Road
preva1 bolero 1359088888 8.47 Ullalu Road
preva1 bolero 1359088986 0 Ullalu Road
preva1 bolero 1359088988 45 Ullalu Road
preva1 bolero 1359088996 21 Ullalu Road
preva1 bolero 1359088998 0 Ullalu Road
preva1 bolero 1359089006 15 Ullalu Road
preva1 bolero 1359089009 12 Ullalu Road
preva1 bolero 1359089006 15 Ullalu Road
preva1 bolero 1359089016 0 Ullalu Road
preva1 bolero 1359089026 0 Ullalu Road

So here i need output table like below:

stoppagedetails:
accountID deviceID from_timestamp to_timestamp diff
--------- -------- ---------- -------- -------------
preva1 bolero 1359088796 1359088888 92
preva1 bolero 1359088986 1359088988 2
preva1 bolero 1359088998 1359089006 8
preva1 bolero 1359089016

How to write mysql query for the above requirement.

View 3 Replies View Related

Query - Select Common Data From One Column And Display In Severalcolumns

Feb 28, 2008

Hello,I have a (big) table which is not normalized, but for i need at themoment i thinkthat's no problem. Indeed, what i would like to do is to select thename field andthe note. The problem is that i want to display the note in 2different columns.the first columns will show the number (count) of time that a certainnote (e.g note=4)appears for a certain name and in the other column the same thing butfor a different note value.so each column noteX will display the number of time that the notewith the value X appears for each namefor example, to the following table:Name | note | job | city | id |----------------------------------------john | 4 | jb1 | hamb | 1 |john | 5 | jb2 | hamb | 2 |john | 5 | jb3 | hamb | 3 |john | 5 | jb4 | hamb | 4 |Mark | 4 | jb1 | mun | 5 |Mark | 4 | jb2 | mun | 6 |Mark | 4 | jb5 | mun | 7 |Mark | 5 | jb1 | mun | 8 |peter | 5 | jb3 | berl | 9 |peter | 5 | jb5 | berl | 10 |frank | 4 | jb6 | v.form | 11 |frank | 5 | jb3 | v.form | 12 |frank | 5 | jb2 | v.form | 13 |the result should be:Name | note5 | note4 |-------------------------john | 3 | 1 |Mark | 1 | 3 |peter | 2 | 0 |frank | 2 | 1 |How should be the right SQL command to show the data i want?Rui DiasJoin Bytes!Thanks a lot

View 5 Replies View Related

Can I Access MS Access Table In A Select Query Of SQL Server

Nov 29, 2006

Is there a way to specify a MS Access table (or query object) in the select query of SQL Server.

Ex.:

MSAccessTable (in file.mdb)



col1
col2

a1
a2

b1
b2

SQL query in SQL Server:

SELECT col1, col2 into SqlTable from [file.mdb].MSAccessTable;

Thanks,

View 3 Replies View Related

Return The Results Of A Select Query In A Column Of Another Select Query.

Feb 8, 2008

Not sure if this is possible, but maybe. I have a table that contains a bunch of logs.
I'm doing something like SELECT * FROM LOGS. The primary key in this table is LogID.
I have another table that contains error messages. Each LogID could have multiple error messages associated with it. To get the error messages.
When I perform my first select query listed above, I would like one of the columns to be populated with ALL the error messages for that particular LogID (SELECT * FROM ERRORS WHERE LogID = MyLogID).
Any thoughts as to how I could accomplish such a daring feat?

View 9 Replies View Related

DB Engine :: Unable To Select Data From A Table Even After Providing Select Access

Aug 28, 2015

I am unable to the access on table even after providing the SELECT permission on table.

Used Query by me :

Here Test is schema ; Card is table ; User is Satish

To grant select on Table

GRANT SELECT ON TEST.Card  TO satish
Even after this it is not working, So provided select on schema also.
used query : GRANT SELECT ON SCHEMA::TEST  TO Satish.

View 8 Replies View Related

Data Access :: Insert Rows To MS Access 2013 Without Listing Column Names

Nov 12, 2015

We need to insert data/rows from a SQL Server 2014 database into MS Access database.  The problem is, there are so many columns (100+) in the table and there are so many insert transactions of this kind (from different tables) that it is not very easy to write the code in VB.NET that lists all column names.

Both the Access and SQL Server tables have the same number of columns and the equivalent data types, so inserting is not really the problem.  It's just that is there a way to do an insert statement in T-SQL that does not name all the columns?

View 3 Replies View Related

Transact SQL :: SELECT On Column Name From Query Result Set In Same Query?

May 9, 2015

I have a column colC in a table myTable that has a value (e.g. '0X'). The position of a non-zero character in column colC refers to the ordinal position of another column in the table myTable (in the aforementioned example, colB).

To get a column name (i.e., colA or colB) from table myTable, I can join ("ON cte.pos = cn.ORDINAL_POSITION") to INFORMATION_SCHEMA.COLUMNS for that table catalog, schema and name. But I want to show the value of what is in that column (e.g., 'ABC'), not just the name. Hoping for:

COLUMN_NAME Value
----------- -----
colB        123
colA        XYZ

I've tried dynamic SQL to no success, probably not executing the concept correctly...

Below is what I have:

CREATE TABLE myTable (colA VARCHAR(3), colB VARCHAR(3), colC VARCHAR(3))
INSERT INTO myTable (colA, colB, colC) VALUES ('ABC', '123', '0X')
INSERT INTO myTable (colA, colB, colC) VALUES ('XYZ', '789', 'X0')
;WITH cte AS
(
SELECT CAST(PATINDEX('%[^0]%', colC) AS SMALLINT) pos, STUFF(colC, 1, PATINDEX('%[^0]%', colC), '') colC

[Code] ....

View 4 Replies View Related

How To Make Select Query To Access View In Other Server

Mar 7, 2007

Dear All,
i am making small web application using asp.net, C# ,sql2000.
i want a about regarding how to access view or table from other server to local server. i have base database where there is a view which need to access in my database of local server.that is how to make select query to access view in other server Please help
thanks 

View 1 Replies View Related

Data Access :: Function Using Select

Oct 15, 2015

if I have table XXXX with columns a,b,c,d,e,f,g,h,i and I need a function or stored procedure.If I use SELECT a,b,c,d from XXXX and the function returns the result set with columns e,f,g,h,i only Means the columns used in Select must not be included in the result set.

View 10 Replies View Related

Select Query For Column

Mar 13, 2008

i have one table called Healthmanagement
in that i have column HealthTitles in that there r so many rows..few of them r here:

HealthTitles
---------------------------------
Lung Health
Lung Health: General
Lung Health: Asperic Detailed Modified
Diseases
Diseases: in one generation
Attacks
Attacks: Health Related

i want in ouput all rows but which r with ':' i want after that part only and if the rows r without ':' then remain as it is:

so i want

HealthTitles
---------------------------------
Lung Health
General
Asperic Detailed Modified
Diseases
in one generation
Attacks
Health Related

how can i get that?
thanks for any help.

View 4 Replies View Related

How Access Records One By One Fetched Using Select Query In Sql Server 2005

May 28, 2008

Hi Friends,
I have created the procedure in sql server 2005 for retriving email addresses from table based on date_expiry and concatinating all email addresses in to @tolist  as shown below
Declare @tolist varchar(8000)
set @tolist = ''SELECT @tolist = @tolist + ';' + COALESCE(email, '')
FROM awc_register
WHERE DATEDIFF(day, date_expiry, GETDATE())='3'print @tolist
 set @tolist = substring(@tolist, 2, len(@tolist))
 and I passed this @tolist to another procedure which should send mails for email addresses present in @tolist variable.
Problem  is I need to send the mail to each email address separatley.( not bulkly)
 
Thanks,
 
 

View 1 Replies View Related

Select Query With Incremental Column On The Fly?

Jul 10, 2007

Hi, all.
I want to Select query with incremental column on the fly.

For example
Use pubs
GO
select * from jobs where job_desc like '%e%' Order by max_lvl
returns
job_idjob_descmin_lvlmax_lvl
1New Hire - Job not specified1010
12Editor25100
13Sales Representative25100
...

I want to add here Rank Column numbering in order
select RankOnTheFly, * from jobs where job_desc like '%e%' Order by max_lvl
Then result will be..
Rankjob_idjob_descmin_lvlmax_lvl
11New Hire - Job not specified1010
212Editor25100
313Sales Representative25100
..

I can get the result using cursor and looping throught and inserting or Using Identity function.
But, I saw before there is just one simple Select query doing that.

Does anyone know this?
Thank you..

View 12 Replies View Related

Null Value In Column In Select Query

Mar 18, 2015

Suppose I have added a xyz bit column in mytable. From now onwards new values inserted in mytable will have 0 or 1 in xyz column but the values that were previously stored will have NULL value in xyz column.

Now I want to write a query in which I will not give xyz parameter always like it can be null or value.

select * from mytable
where class='something'
and xyz is null

or

select * from mytable
where class='something'
and xyz = 1

Now how to write same query for both cases.

View 9 Replies View Related

Add A Column Based On A Select Query

Mar 5, 2006

Supose I have the following select:

Select Name, Age, (select TelNums from Telephone)
From Person

The problem is that (select TelNums from Telephone) can return more than 1 record:

tel1
tel2
.
.
.

I was wondering how I can make a select to return the tel numbers like: 'tel1,tel2,tel2'

»»» Ken.A

View 3 Replies View Related

ACCESS SQL COLUMN DATA TYPE

Oct 19, 2007

HELLO
i have an sql server database, with a table an some columns.
how can i get the data type of each column and the lengh define in the database table?
 

View 4 Replies View Related

Data Access :: Finding Min Value Corresponding To Other Column

Aug 12, 2015

Query :-

 SELECT
 MAX(TIME_VAL)  AS  Duration1 ,
 MIN(TIME_VAL)  AS  Duration2 , 
 --  VALUE OF LATITUDE CORRSPONDING TO  MAX(TIME_VAL)
 --  VALUE OF LATITUDE CORRSPONDING TO  MIN(TIME_VAL)
  (Select LONGITUDE from (select LONGITUDE ,  row_number()
   
[Code] ....

I am not getting Correct values for StartLongitude , EndLongitude. How can i achieve this to get the val of latitude corssponding to max/ min of time_val column.

View 3 Replies View Related

Data Access :: Select After Check Previous Records

May 5, 2015

I have two tables. Users and records. I need to select only the users that not has lines recorded in the other table. How could I do that?

Example:

ID| Name| Access 1|Access 2|
----------------------------
1 | Axel   | True         |False   |
2 | Ivan  | False        |False   |
3 | Bob  | True          |False   |
4 | Sue  | False         |False   |

ID| Points| Month| Year|User_1|User_2|
--------------------------------------
1 |  2      |    5 | 2015|   2  |   1  |
2 |  5      |    5 | 2015|   2  |   1  |
3 |  1      |    5 | 2015|   3  |   1  |

Then I want to run a select in the users table, only with the users that hasn't records in the second table.

In the example, the second table has User_1 as the user who receives the points and the User_2 is the user who give the points. Then I would know what user didn't receive 'points' yet.

View 3 Replies View Related

Format Of DateTime Column In SELECT Query

Dec 19, 2006

I am using SQL2005 and ASP.NET 2.0
I have one column in database called DateTime and it is defined like type datetime.It is formated like: day.month.year hour:minutes:seconds
My question is: I want to get date from Column DateTime in format day.month.year in SELECT query, not in stored procedure.
 thanks

View 3 Replies View Related

SELECT Query (rows Returned In One Column)?

Aug 17, 2005

Hi there,

I¡¦ve got a table with the following as well as other info:

User ID
DirectoryTypeID (int)
Region ID (int)

I need to run a query where I could get the region ID, then, in the second column, I¡¦d get all distinct directory types within that region. For example, if I run the query:

subRegionAreaID directoryTypeID
--------------- ---------------
3 1
3 2
3 3
3 9

If need these results to be:

subRegionAreaID directoryTypeID
--------------- ---------------
3 1, 2, 3, 9

Is this possible?

Many Thanks!! ļ


Grazi

View 1 Replies View Related

Data Access :: How To Get Column Datatype Using Namespace

Jan 2, 2013

which is to parse a create table script using Microsoft.SqlServer.TransactSql.ScriptDom namespace..I get a list of statements : StatementList SQLStatement = parser.ParseStatementList(StreamReader, out errors);then I cast a relevant statement to the CreateTableStatement type which gives me access to the ColumnDefinition class.

foreach (TSqlStatement T in SQLStatement.Statements)
{ if (T is CreateTableStatement) { CreateTableStatement  TC= (CreateTableStatement)T}}
with foreach (ColumnDefinition CD in TC.Definition.ColumnDefinitions)

I am ready to loop through the columns so far so good. I can get to the column name using CD.ColumnIdetifier.Value, to the data type using CD.DataType.Name.BaseIdentifier.Value, but can't seem to get to the length definition. Meaning, I can get column1 , varchar; but I need column1, varchar(40). where do I get (40) from?I tried using ScriptTokenStream under C.DataType, but it seems to iterate through all tokens not just ones relevant to that fragment.

View 6 Replies View Related

Data Access :: Query On View To Get A Single Batched Data

Nov 25, 2015

I have a view that  give me the data of all the batched. Now I am using a query on view to get a single batched data. when I am using direct query it was taking 0 sec but when I am using Through view "select *  from myView where batched=2" then its taking 30 mnt.

View 3 Replies View Related

Data Access :: How To Find Column Names In A Table

Sep 11, 2015

how to find the columns names in a table in sql 2008r2.

as i need to compare the midsing fields in the table from two database.

View 3 Replies View Related

Data Access :: Identity Column Jump1000 Record In Once

Oct 7, 2015

I have table contains more columns  and first column have ID  int not null primary key  and auto increment by 1 seed by 1 the ID 165000 record  and instant Jump to 166000 and increment by 1 ...

View 5 Replies View Related

SQL Server 2008 :: SELECT On Column Name From Querys Resultset In Same Query?

May 9, 2015

I have a column colC in a table myTable that has a value (e.g. '0X'). The position of a non-zero character in column colC refers to the ordinal position of another column in the table myTable (in the aforementioned example, colB).To get a column name (i.e., colA or colB) from table myTable, I can join ("ON cte.pos = cn.ORDINAL_POSITION") to INFORMATION_SCHEMA.COLUMNS for that table catalog, schema and name. But I want to show the value of what is in that column (e.g., 'ABC'), not just the name. Hoping for:

COLUMN_NAME Value
----------- -----
colB 123
colA XYZ

I've tried dynamic SQL to no success, probably not executing the concept correctly..Below is what I have:

CREATE TABLE myTable (colA VARCHAR(3), colB VARCHAR(3), colC VARCHAR(3))
INSERT INTO myTable (colA, colB, colC) VALUES ('ABC', '123', '0X')
INSERT INTO myTable (colA, colB, colC) VALUES ('XYZ', '789', 'X0')

;WITH cte AS
(
SELECT CAST(PATINDEX('%[^0]%', colC) AS SMALLINT) pos, STUFF(colC, 1, PATINDEX('%[^0]%', colC), '') colC
FROM myTable

[code]....

View 5 Replies View Related

HELP With SQL Query: Select Multiple Values From One Column Based On &&<= Condition.

Aug 7, 2007

Hello all. I hope someone can offer me some help. I'm trying to construct a SQL statement that will be run on a Dataset that I have. The trick is that there are many conditions that can apply. I'll describe my situation:

I have about 1700 records in a datatable titled "AISC_Shapes_Table" with 49 columns. What I would like to do is allow the user of my VB application to 'create' a custom query (i.e. advanced search). For now, I'll just discuss two columns; The Section Label titled "AISC_MANUAL_LABEL" and the Weight column "W". The data appears in the following manner:

(AISC_Shapes_Table)

AISC_MANUAL_LABEL W
W44x300 300
W42x200 200
(and so on)
WT22x150 150
WT21x100 100

(and so on)
MT12.5x12.4 12.4
MT12x10 10
(etc.)

I have a listbox which users can select MULTIPLE "Manual Labels" or shapes. They then select a property (W for weight, in this case) and a limitation (greater than a value, less than a value, or between two values). From all this, I create a custom Query string or filter to apply to my BindingSource.Filter method. However I have to use the % wildcard to deal with exceptions. If the user only wants W shapes, I use "...LIKE 'W%'" and "...NOT LIKE 'WT%" to be sure to select ONLY W shapes and no WT's. The problems arises, however, when the user wants multiple shapes in general. If I want to select all the "AISC_MANUAL_LABEL" values with W <= 40, I can't do it. An example of a statement I tried to use to select WT% Labels and MT% labels with weight (W)<=100 is:




Code SnippetSELECT AISC_MANUAL_LABEL, W
FROM AISC_Shape_Table
WHERE (W <= 100) AND ((AISC_MANUAL_LABEL LIKE 'MT%') AND (AISC_MANUAL_LABEL LIKE 'WT%'))



It returns a NULL value to me, which i know is NOT because no such values exist. So, I further investigated and tried to use a subquery seeing if IN, ANY, or ALL would work, but to no avail. Can anyone offer up any suggestions? I know that if I can get an example of ONE of them to work, then I'll easily be able to apply it to all of my cases. Otherwise, am I just going about this the hard way or is it even possible? Please, ANY suggestions will help. Thank you in advance.

Regards,

Steve G.



View 4 Replies View Related

SQL 2012 :: Allow User To Select Data Through A View But Not Restrict Access To Underlying Table?

Sep 29, 2015

I have two databases DB1 and DB2 DB1 has a source table named 'Source' I have created a login 'Test_user' in DB2 with Public access. I have also created a view named 'Test_view' in DB2 which references data from DB1.dbo.Source

How can I do the following: AS A Test_user

SELECT * FROM DB2.dbo.Test_view --Should work

SELECT * FROM DB1.dbo.Source --Should Not work

View 2 Replies View Related

Transact SQL :: Allow A User To Select Data Through A View But Not Restrict Access To Underlying Table

Sep 29, 2015

I have two databases DB1 and DB2 DB1 has a source table named 'Source' I have created a login 'Test_user' in DB2 with Public access. I have also created a view named 'Test_view' in DB2 which references data from DB1.dbo.Source

How can I do the following: AS A Test_user

SELECT * FROM DB2.dbo.Test_view --Should work

SELECT * FROM DB1.dbo.Source --Should Not work

View 3 Replies View Related

Select Distinct Column Data With Other Values From The Table

Dec 16, 2004

I have a table 'wRelated' with the following columns

[related_id] [int]
[channel_id] [int]
[mui] [varchar]
[price_group_id]
[type_id] [int]
[related_mui] [varchar] (100)
[date_started] [smalldatetime]
[date_ended] [smalldatetime]
[date_entered] [datetime]
[deleted] [tinyint],
[rank] [int]
data in column [mui] is repeated as the table has more than one entries for the same [mui],
The requirement is to select the distinct[mui] but value in all the other columns for the same mui should be select in the next row with null for the same [mui]
The recordset expected should be something like this.

[mui],[related_mui],[price_group_id],[date_entered],[date_ended] m123,rm345,'pr','12-10-2003',12-12-2004'
null,rm789,'ar','12-1-2003',26-2-2004'
null,rm999,'xy','14-12-2002',12-2-2004'
m777,rm889,'pr','12-12-2004',12-12-2004'
null,rm785,'yy','1-10-2002',12-12-2004'
m888,rm345,'pr','2-8-2003',12-12-2004'
null,rm345,'tt','30-7-2002',12-12-2004'

I have tried Unions and temporary table inserts.

View 1 Replies View Related

Trigger Not Running When Trying To Select Data From A Column That Is Being Updated?

Dec 11, 2006

Trigger not running when trying to select data from a column that is being updated?

View 1 Replies View Related

SELECT * View Returning Wrong Column Data

Oct 16, 2007

SQL 2005 9.00.3402.00 (x64) As Above really when I select * OR select a single column from the view the wrong column data is returned. in SQL Management Studio when I expand the Columns of the view it reflects the old table structure not the new table structure. I can easily fix by compiling the view again but this would mean I would have to recompile all referencing views when I make a change to table structures. I've tried various DBCC Clean Buffers & drop cache with no effect. Is there a command to recompile all views & poss stored procs in a database. Any help or explanation would be appreciated GW

View 12 Replies View Related

Transact SQL :: How To Select Data With Specific Priority Of A Column

Aug 1, 2015

i have table that has rows as below

DECLARE @Table TABLE
(minv_code INT,
alert_msg varchar(10),
alert_time Datetime)

[code]...

i want to select the data priority wise. the o/p should look like 

e.g first row - 873939, 'Meter', '7/24/2015 3:31:22'
second row - 873939, 'Tamper', '7/24/2015 3:30:00'
third row - 873939, 'Reverse', '7/24/2015 3:31:18'
fourth row -873940, 'Tamper', '7/24/2015 3:31:22' 
fifth row - 873940, 'Reverse', '7/24/2015 3:30:00'

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved