Need Single Select Query
Feb 8, 2007
Hello Everyone,
Consider the below table
DocNbr Cheques
00001 101010
00002 101010
00002 102020
00003 103030
00004 103030
00004 104040
00005 105050
I just need the single select to result the docnbr which is repeating the values. In the above case I want my result like below where the DocNbr 00002 and 00004 repeated their values.
DocNbr Cheques
00002 101010
00002 102020
00004 103030
00004 104040
Thanks in advance,
Senthil .G
Note: I do not consider if the cheque contain repeated values
View 3 Replies
ADVERTISEMENT
Oct 2, 2007
Hello,
I have a question which was given to me in a test. Question is :: print value from 1-20 in a single column using single select query without using any table.
If any one have solution, then please help me.
View 18 Replies
View Related
Sep 13, 2006
i just can't find a way to perform this Select Query in my ASP.Net page. I just want to find out the sales for a certain period[startDate - endDate] for each Region that will be selected in the checkbox. Table Sales Fields: SalesID | RegionID | Date | Amount This is how the interface looks like.Thank You.
View 1 Replies
View Related
Mar 18, 2015
How to convert float to timestamp in single select query
E.g., i have float as 1.251152515236 ,
I want to convert this to datetime and from datetime to timestamp... i.e. 26:11:00
View 1 Replies
View Related
May 25, 2015
Here the SELECT query is fetching the records corresponding to ITEM_DESCRIPTION in 5 separate transactions. How to change the cursor to display the 5 records in at a time in single transactions.
CREATE TABLE #ITEMS (ITEM_ID uniqueidentifier NOT NULL, ITEM_DESCRIPTION VARCHAR(250) NOT NULL)INSERT INTO #ITEMSVALUES(NEWID(), 'This is a wonderful car'),(NEWID(), 'This is a fast bike'),(NEWID(), 'This is a expensive aeroplane'),(NEWID(), 'This is a cheap bicycle'),(NEWID(), 'This is a dream holiday')
---
DECLARE @ITEM_ID uniqueidentifier
DECLARE ITEM_CURSOR CURSOR
[Code] ....
View 1 Replies
View Related
Mar 1, 2008
Hi,
i have an input parameter @PageloadYN Bit Null
if @PageloadYN = 1 then Select top 500 Records from the Table
if @PageloadYN = 0 then Select * from the Table
i tried like this
Select top 500.* From Table where @PageloadYN = 1
Select * From Table where @PageloadYN = 0
Is there any way to get details in Single select statement only.
View 2 Replies
View Related
Jul 19, 2006
Just wondering, in DTS, can I run a SELECT script that selects from 2 different databases (both on the same server)?
I can run this in Sql Query Analyzer, but in a DTS, it doesnt accept my database name prefixes:
SELECT
a.something
FROM
DB_ONE.dbo.product a, DB_ONE.dbo.mp_brand b, DB_TWO.dbo.lk_pcat_cutover c
WHERE
a.PCat <> c.Pcat
(where DB_ONE and DB_TWO are the 2 different db names)
I have one connection to DB_ONE... does this mean I cant access DB_TWO when using this connection? I want to try and avoid using a temporay table for storing DB_TWO's data in DB_ONE... Is this possible?
Thanks,
Andre
View 1 Replies
View Related
Aug 19, 2006
Hello everyone, I've got a bit of an SQL mystery that I'm not sure how to solve. For some reason I just cant get my head around it. Here's the scenario:
Table A:
_____________
BidID - Int identity
AuctionID - int
BiderName - varchar(50)
bidAmount - money
______________________
Now obviously each Bid will have a Unique ID using BidID but the other rows will contain multiple bids per user, on many different items possibly.
BidID AuctionID BiderName BidAmount
1 4005 joeblow 100.00
2 4005 janedoe 101.00
3 4005 joeblow 107.00
4 4006 joeblow 100.00
5 4006 janedoe 105.00
6 4006 joeblow 106.00
I need to find out which Auctions JoeBlow is bidding on, but I dont need a table with Rows for every single one of his bids, just a distinct auctionID for his top bid so in this case the only thing returned would be
3 4005 joeblow 107.00
6 4006 joeblow 106.00
Any clues? I've been through sub querys, and stored procedures, and I cant get anything to work quite right.
Thanks in advance for your help.
View 4 Replies
View Related
Aug 4, 2000
SELECT * on a 4000 row table is taking more than 12 seconds.
Other larger tables are not nearly as slow.
I've DBCC dbreindex'd, and dbcc showcontig shows density at 100%.
How can I figure out why this is happening?
What are some remedies?
Thanks for your help.
View 1 Replies
View Related
Aug 20, 2007
Hi,
I have several row records in which
name email
--------- ---------
name1 abc@abc.com
name2 abc@abc.com
name3 abc@abc.com
name4 123@123.com
name6 123@123.com
How should I write the query which can return records with unique email address with any name attached?
The expected record set will be
name email
--------- ---------
<any> abc@abc.com
<any> 123@123.com
I was thinking to select the distinct of email and just stuck at here. I encountered this problem few times and still cannot solve it. Any help will great appreciated. Thanks in advance.
View 7 Replies
View Related
Jun 3, 2008
Hi,
I am using a SP which one has lot of Joins(More than 10 tables).
For every request from user SP executed, and the DB performance got slow.
For this i planned to write a schedule which runs once in an hour to put all the results of SP in to One single table.
I thought if the user selects from single table means the performance will increase.
I don't know whether this one is a right solution.
I am very new to SQL server. Help me for this Problem.
Thanks in advance.
View 1 Replies
View Related
Jun 3, 2008
Hi,
I am using a SP which one has lot of Joins(More than 10 tables).
For every request from user SP executed, and the DB performance got slow.
For this i planned to write a schedule which runs once in an hour to put all the results of SP in to One single table.
I thought if the user selects from single table means the performance will increase.
I don't know whether this one is a right solution.
I am very new to SQL server. Help me for this Problem.
Thanks in advance.
View 6 Replies
View Related
May 11, 2006
Can somebody please tell me whether the following syntax is supportedor whether it's a "feature" that will someday stop working. It works inboth SQL Server 2000 and 2005 at the moment.declare @var varchar(1000)set @var = ''select @var = @var + colx from some_table where col1 = some_valuecolx is a varchar or at least is cast to one as part of the selectstatement. If the where clause would normally return more than one row,all returned values for colx are concatenated into @var.I've not seen this syntax before but that doesn't make it wrong ;-)Malc.
View 8 Replies
View Related
Apr 22, 2005
The LIKE keyword in SELECT WHERE can use wildcard
%
Any string of zero or more characters.
_
Any single character.
but how to Pattern Matching for "zero or single character"?
View 10 Replies
View Related
Aug 18, 2007
define @strName as varchar(50) NULL
set @strName=(SELECT strname from Table)
SELECT '+ @strName +' from Table
It does not work
View 1 Replies
View Related
Mar 18, 2015
how to convert float to timestamp in single select query..for exp. i have float as 1.251152515236 ,i want to convert this to datetime and from datetime to timestamp... i.e. 26:11:00
View 6 Replies
View Related
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
May 27, 2008
Hi,
I have a table -- Table1.
It has two columns -- Name and Alpha.
Alpha has comma separated values like -- (A,B,C,D,E,F), (E,F), (D,E,F), (F), (A,B,C).
I need to pick the values of column -- Name , where in values of Alpha is less than or equal to 'D'.
I tried <=, but got only values less than 'D', but was not able to get equal to 'D'.
Any suggestions??
View 4 Replies
View Related
Sep 8, 2004
I have to write a statement that answers the question:
"Which pilot is authorized to fly all the aircraft in the fleet?" implying that the individual aircraft could be of any of the three aircraft types.
Below are the tables with notation Tbl_name (important keys [clarification of keys]):
personnel (pers_id, name, crew_role [eg. pilot, stewardess]),
aircraft (craft_id, type_designation [eg. Boeing737], craft_name [eg. The Viking, Icarus]),
aircraft_type (type_designation), and
authorization (pers_id, type_designation).
In words my question should be something like:
"For all those who are authorized to fly aircraft (the only pers_id:s listed in the authorization table), show the names of those that have their pers_id:s next to all aircraft_type:s."
I've gotten this far:
Code:
SELECT DISTINCT p.name
FROM personnel AS p, authorization AS b, aircraft_type AS f
WHERE p.pers_id = b.pers_id
AND b.type_designation = ... ;
Now what I want to accomplish is to select the pilot which has a record for ALL type_designation entries in the aircraft_type table.
Is there a magic keyword that I don't know of? Is that magic keyword called "EXIST" and how do I use it?
Best regards,
rod
View 2 Replies
View Related
Jun 8, 2015
I have the following two tables...
tblServer
-serverID
-serverName
-serverLocation
tblSite
-siteID
-serverID
-siteName
-siteIpAddress
I need to write a select query that gets the values of all columns but only returns unique sites because some sites are load balanced across several servers and where this is the case I don't want the site to appear multiple times in the list.
View 4 Replies
View Related
May 19, 2008
Hi,
I have used several sql queris to generate a report. This queries pull out data from different tables. But sometimes at the same table too.
Basically those are SELECT statements.
I have created stored proc for each SELECT statement. now I'm wondering can I include all SELECT statements in one stored proc and run the report.
If possible, can anyone show me the format?
Thanks
View 4 Replies
View Related
Sep 16, 2015
My tables look like this:
 Users //
table
 UserID // pk
 UserName // varchar
UserFamilyName // varchar
User_Friends //
table
 FriendsID // pk
 UserID // fk
 FamilyName // varchar
MY query:
 SELECT
U.UserFamilyName, F.FamilyName
 FROM Â
Users U LEFT
JOIN User_Friends
F ON U.UserID =Â
F.UserID
 WHERE    Â
U.UserName = ‘JOHN’
How do I adjust my query to select just the very first record from Users_friends, I want only the top first one.And if there are no friends how can I return an empty string instead of Null.
View 10 Replies
View Related
Aug 18, 2015
how we can replace the multiple values in a single select statement? I have to build the output based on values stored in a table. Please see below the sample input and expected output.
DECLARE @V1 NVARCHAR(100)
SELECT @V1 = 'FirstName: @FN, LastName: @LN, Add1: @A1, Add2: @A2 '
DECLARE @T1 TABLE
(FN VARCHAR(100), LN VARCHAR(100), A1 VARCHAR(100), A2 VARCHAR(100))
[code]....
View 7 Replies
View Related
Aug 31, 2015
Below. I have also pasted the current result of this query and the desired result.Â
Query can be updated to get the desired result as given below?
Query:
Select c.OTH_PAYER_ID, c.PAID_DATE, f.GROUP_CODE, f.REASON_CODE, f.ADJUSTMENT_AMOUNT
From MMIT_CLAIM_ITEM b, mmit_tpl c , mmit_attachment_link d, MMIT_TPL_GROUP_RSN_ADJ f
where b.CLAIM_ICN_NU = d.CLAIM_ICN and b.CLAIM_ITEM_LINE_NU = d.CLAIM_LINE_NUM and c.TPL_TS = d.TPL_TS and f.TPL_TS = c.TPL_TS and b.CLAIM_ICN_NU = '123456788444'
Current Result which I am getting with this query
OTH_PAYER_ID PAID_DATE GROUP_CODE REASON_CODE ADJUSTMENT_AMOUNT
5501 07/13/2015 CO 11 23.87
5501 07/13/2015 PR 12 3.76
5501 07/13/2015 OT 32 33.45
2032 07/14/2015 CO 12 23.87
2032 07/14/2015 OT 14 43.01
Desired/Expected Result for which I need updated query
OTH_PAYER_ID PAID_DATE GROUP_CODE_1 REASON_CODE_1 ADJUSTMENT_AMOUNT_1 GROUP_CODE_2
REASON_CODE_2 ADJUSTMENT_AMOUNT_2 GROUP_CODE_3 REASON_CODE_3 ADJUSTMENT_AMOUNT_3
5501 07/13/2015 CO 11 23.87 PR 12 3.76 OT 32 33.45 2032 07/14/2015 CO 12 23.87 OT 14 43.01
Using DB2.
View 2 Replies
View Related
Feb 12, 2014
I have created a trigger that is set off every time a new item has been added to TableA.The trigger then inserts 4 rows into TableB that contains two columns (item, task type).
Each row will have the same item, but with a different task type.ie.
TableA.item, 'Planning'
TableA.item, 'Design'
TableA.item, 'Program'
TableA.item, 'Production'
How can I do this with tSQL using a single select statement?
View 6 Replies
View Related
Aug 16, 2015
I want to recursively select all records within a hierarchy, using the main parentid and a textvalue on level 1 OR level 2 of the subcategories.
My data:
CREATE TABLE [dbo].[articlegroups](
[id] [int] NOT NULL,
[parentid] [int] NOT NULL,
[catlevel] [tinyint] NOT NULL,
[slug_en] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_globos_articlegroups] PRIMARY KEY CLUSTERED
[Code] ...
When selecting rows I always have the main parentId (so catlevel 0) and the slug_en value.
In my example case I have id 129 and slug_en='cradles'.
I want my query to then return:
idparentidcatlevel
12900
1301291
1361302If I have id 129 and slug_en='pillows'.
I want my query to then return:
idparentidcatlevel
12900
1391291
How can I do this? I'm new to SQL Server. I was reading here [URL] .... on recursive SQL, but how to implement this as I just have one table and I also have 2 selection criteria (main category id and a text value on either level 1 or 2).
View 9 Replies
View Related
Sep 6, 2006
Hi, not exactly too sure if this can be done but I have a need to run a query which will return a list of values from 1 column. Then I need to iterate this list to produce the resultset for return.
This is implemented as a stored procedure
declare @OwnerIdent varchar(7)
set @OwnerIdent='A12345B'
SELECT table1.val1 FROM table1 INNER JOIN table2
ON table1. Ident = table2.Ident
WHERE table2.Ident = @OwnerIdent
'Now for each result of the above I need to run the below query
SELECT Clients.Name , Clients.Address1 ,
Clients.BPhone, Clients.email
FROM Clients INNER JOIN Growers ON Clients.ClientKey = Growers.ClientKey
WHERE Growers.PIN = @newpin)
'@newpin being the result from first query
Any help appreciated
View 4 Replies
View Related
Jun 14, 2007
Hi,
I have received a text file in the following format:
MthYear Customer Quantity Price Total
Apr2003 Allan 100 5 500
--------- Austin 25 2 50
--------- George 1500 1 1500
---------- Jessy 200 2 400
Apr2004 Jerry 600 3 1800
--------- Stella 250 2 500
June2005 XXXX 50 5 250
I am exporting this text file in Sql Server database table. After exporting I need to Update the MtnYear field marked as ------- to appropriate year. ie
The MthYear field for Austin, George,Jessy should be updated with Apr2003,
The MthYear field for Stella should be updated with Apr2004
iiily, for other records. Let me inform if this is possible with the help of a single query or any better way of doing it. The records that i need to update is more than 2 lakhs. I am sorry if u feel this questionis not apropriate.
View 3 Replies
View Related
Jan 7, 2007
Hello
I have a sql query that shows the top N numbers of records and also wanted to show the total numbers of this records.
Code:
.
.
.
rs_1.Open "SELECT top 5 msg_id, message, topic_id, last_post_by, id, sdate FROM forum_table",conn,1,3
rs_2.Open "SELECT msg_id, message, topic_id, last_post_by, id, sdate FROM forum_table",conn,1,3 “
Top number to show: <%=rs_1.recordcount%>
Total number of records in database: <%=rs_2.recordcount%>
.
.
.
As you can see, it is only on the same database that I am querying. How do I make a single sql query out of this?
View 3 Replies
View Related
Jul 6, 2004
i hav a table of the form
table EMP
(
EMPNAME varchar(50)
)
and the data in the table is
record #1 abc
record #2 abc
record #3 abc
record #4 abc
record #5 abc
record #6 abc
can i use a single query so as to retain a single record in the table and remove the rest ?
View 14 Replies
View Related
Mar 13, 2008
I have the following table:
id geounit parentgeounit
Here's some sample data:
1 Northeast null
2 Southeast null
3 New Jersey 1
4 Florida 2
Basically I need to return the parentgeounit's name, for instance for record #4 I'd want to return
4 Florida Southeast
Instead of:
4 Florida 2
Can this be accomplished?
View 3 Replies
View Related
Oct 29, 2006
So I have code to fill my repeater with a data: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim cnn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("db_ConnStr").ConnectionString) Dim cmd1 As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter("SELECT aspnet_Users.UserName, COUNT(forum_posts.post_id) AS IlePost, forum_posts_1.post_content, forum_posts_1.topic_id, forum_posts_1.post_id, forum_posts_1.post_date FROM aspnet_Users INNER JOIN forum_posts ON aspnet_Users.uID = forum_posts.user_id INNER JOIN forum_posts AS forum_posts_1 ON aspnet_Users.uID = forum_posts_1.user_id GROUP BY aspnet_Users.UserName, forum_posts_1.post_content, forum_posts_1.topic_id, forum_posts_1.post_id, forum_posts_1.post_date HAVING (forum_posts_1.topic_id = @topic_id) ORDER BY forum_posts_1.post_date ASC", cnn) cmd1.SelectCommand.Parameters.AddWithValue("@topic_id", Request.QueryString("ID")) Dim ds As Data.DataSet = New Data.DataSet cnn.Open() cmd1.Fill(ds, "posts") Repeater1.DataSource = ds.Tables("posts") Page.DataBind() cnn.Close() End Sub And I want to take the value from column which I bolded - IlePost. I want take this out at compare with some condition. For example:Dim label as label = Repeater1.Findcontrol("Label1")If COLUMN < 10 thenlabel.text = "Less than 10"elselabel.text = "More than 10"I hope you understand me :-)
View 1 Replies
View Related
Apr 29, 2008
Table Name:-emp
table structure:- Name Gender
A Male
B Male
C FeMale
D FeMale
I want only one update query to update this table like this
table structure:- Name Gender
A FeMale
B FeMale
C Male
D Male
please help me?
View 1 Replies
View Related