Howto Add More Column Into Select Record?

Aug 16, 2006

hi, good day,

i have try following to get the records of the existing folder using :


insert into my_table
exec xp_dirtree 'c: emp'


for example , it give the result

subdirectory depth
--------------------
another 1
TEST 1
txtfiles 1
anotherSub 2



my question is , can i have add another column maindirectory into this existing result ?
and my expected result would like to be as follow

main directory subdirectory depth
--------------------------------------

another another 1
TEST TEST 1
txtfiles txtfiles 1
TEST anotherSub 2


is it possible ? thanks for guidance

View 5 Replies


ADVERTISEMENT

Howto: Delete Every Second Record If Duplicates

Jul 19, 2007

Hi.I have a "union" table which results of a union of two tables.Occasionally I could have duplicates, when the same PIN has been addedto both tables, albeit at different Datees/Times, such as:PINNameAdded Date100411A7/11/2007 10:12:58 AM100411A7/17/2007 10:54:23 AM100413B7/11/2007 10:13:28 AM100413B7/17/2007 10:54:39 AM104229C7/6/2007 2:34:13 PM104231D7/6/2007 2:34:25 PM104869E6/10/2007 11:59:12 AM104869E6/22/2007 2:40:18 PMThe question is - how can I delete by queries the first occurence(time-wise) of these duplicates - i.e. I would want to delete thefirst occurence of 100411 (A), the first occurence of 100413 (B), andthe first occurence of 104869 (E) in the example above - records C andD show only once, so they are fine.Is there a MsAccess solution ? Is there a SQL-server solution ?Thank you very much !Alex

View 2 Replies View Related

Select Distinct Record Only If Certain Column Not Null

Apr 5, 2007

Been trying to come up with a query to filter-down my sample set intodistinct records. For instance, lets say column1 is a sample set,column2 is the parameter, and column3 is a name and column4 is a type(lets also say there is a fifth column (id) that is an id). What Ineed is one record per type per sample only if type is given, if not,then return that record as well.I've used a subquery to get as close to the desired query is aspossible:select * from table1where id in (select min(id) from table1where column1="A"group by column1, column2)Here's an example of all data for sample "A":1 2 3 4----------A 1 X PA 1 Y PA 1 Z PA 2 WA 3 WA 4 T PA 5 U PA 6 V PA 7 TA 7 UA 7 VI want output :1 2 3-------A 1 X PA 2 WA 3 WA 4 T PA 5 U PA 6 V PA 7 TA 7 UA 7 VExcept the above query will exclude the last two records becausecolumn3 is not 'grouped by'.Basically I need to reduce any 'range' of records per sample (columna) where column4 is not null (ie = 'P'), to only one record andkeeping all others. Thanks in advance:-B

View 6 Replies View Related

How To: Mutiple Select Statements Where 2nd Uses Column Value For Each Record From The First

Jul 16, 2006

To clarify, I'm trying to create a hiearchial grid that will display projects and their sub projects.

The page the sproc is servicing is a search page where a user can display all projects by a customer or they can enter in a projectID and return info that way.  Thus you'll see If else in what I have listed below.  I highlighted in red the 2nd select statement I'm trying to get to run.  One problem is I'm getting an error:

Msg 156, Level 15, State 1, Procedure sp_GetProjects, Line 33

Incorrect syntax near the keyword 'ELSE'.

Think this has something to do with me trying to run 2 select statements in an IF.  Secondly, I'm not sure exactly what syntax I need to use to accomplish what I'm trying to do.  Again, the first select statement is creating a table with all projects that match the passed custID, the second select statement I'm trying to generate a 2nd table that will take the projectID for each row returned to the first table and find all rows with the same projectID's in the BillGroup table.

 I need these two tables returned to a dataset I'm populated with a sqldataadapter in .net so I can create a relationship between the two tables and then bind to a grid.

 

@custID nchar(25) = NULL,

@projectID bigint = NULL

IF @custID != 'null'

   SELECT p.projectID, p.Description FROM Projects p

    WHERE custID = @custID



     SELECT * FROM Projects p

     JOIN dbo.BillGroups bg ON p.projectID = bg.projectID



ELSE IF @projectID != -1

   SELECT projectID, Description FROM Projects



   WHERE projectID = @projectID

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

-- Insert statements for procedure here



END

View 3 Replies View Related

HOWTO Select Several Rows In One Comma- Separated

Aug 21, 2007

Hello!!

First of all, thank you in advance for helping me!!!

My problem is that I have a BBDD with a table like this (in Oracle and in MySql, both)

E.g.

+---------+-----------+
| groupId | serviceId |
+---------+-----------+
| grup1 | service1 |
| grup1 | service2 |
| grup1 | service3 |
| grup2 | service1 |
| grup2 | service2 |
+---------+-----------+

And I need to do a select o a procedure or something that returns me something like this:

+---------+------------------------------------------+
| groupId | serviceId |
+---------+------------------------------------------+
| grup1 | service1, service2, service3 |
+---------+------------------------------------------+

Is this possible in any way????

Than you very very much.

Almu

View 5 Replies View Related

Howto Set Access Recordsource Onto A Select Sproc

Sep 29, 2005

Hi. I have lots of processing to do on the server - from the client(Access) I call a sproc which returns a recordset (the sproc isessentially a big "select"). With the obtained data , I need togenerate a report. How do I set the Recordsource of the report to theresult of the select sproc ?I have tried the following, but it does not work.Private Sub cmdReport_Click()On Error GoTo cmdReport_ClickErrorDim objCmd As ADODB.CommandDim intOpenObjects As IntegerDim rsTemp As ADODB.RecordsetSet objCmd = New ADODB.CommandintOpenObjects = 1objCmd.ActiveConnection = m_objConnobjCmd.CommandType = adCmdStoredProcobjCmd.CommandText = "_TestReport"Set rsTemp = objCmd.ExecuteintOpenObjects = 2Dim rpt As ReportDoCmd.OpenReport "TestReport", acViewDesignSet rpt = Reports("TestReport")Set rpt.RecordSource = rsTempDoCmd.Close acReport, "TestReport", acSaveYesSet rpt = NothingDoCmd.OpenReport "TestReport", acViewPreviewDoCmd.OpenReport "TestReport", acViewPreviewDoCmd.SelectObject acReport, "TestReport"DoCmd.MaximizecmdReport_ClickExit:If intOpenObjects = 2 ThenrsTemp.CloseSet rsTemp = NothingintOpenObjects = 1End IfIf intOpenObjects = 1 ThenSet objCmd = NothingintOpenObjects = 0End IfExit SubcmdReport_ClickError:MsgBox Err.Description, vbCritical, Me.NameResume cmdReport_ClickExitEnd SubHow can I do that, please ? Would it maybe be better to change the"Select" sproc into an Insert sproc, as in "SELECT... INTO TEMP", inorder to create a temp table on the server, then in Access link to thattable and set the recordsource onto the linked table ?Please help. Thank you very much, Alex.

View 3 Replies View Related

Howto Use The Query Results As View Column?

Sep 17, 2006

Hi All,I have two tables, one is about member infomations, the other is thecatergoriesmember_info(id,name,email,phone)member_categories(id,category)how can create a view like this (id, name, category1, category2,category3) with high performance?Thanks in advance.Joshua

View 2 Replies View Related

Howto Do Totaling In Column Wide In Matrix Table

Jun 14, 2005

Hi

View 10 Replies View Related

How To Create An Copy Of A Certain Record Except One Specific Column That Must Be Different && Insert The New Record In The Table

Sep 1, 2006

Hi
I have a table with a user column and other columns. User column id the primary key.

I want to create a copy of the record where the user="user1" and insert that copy in the same table in a new created record. But I want the new record to have a value of "user2" in the user column instead of "user1" since it's a primary key

Thanks.

View 6 Replies View Related

Column Locked In Record Even Though No One Accessing Record

Mar 18, 2008



Hello. I have a database with a record that has two columns locked. descrip1 and descrip2. they are both nvarchar(max) columns. These are the only two columns of the record that remain locked. I am certain no user is accessing the record. I have even moved a backup of the database to my testing computer and the lock still exists. How do I remove the lock from these two columns on that particular record.

I can edit these two columns on other records. I have researched "Unlock" on MSDN but it doesn't seem to apply to t-sql. Any help would be greatly appreciated.

Thanks. Gary.

View 4 Replies View Related

Can I Use SELECT Statement To Select First 100 Record????

Apr 21, 1999

I would like to exec a select statement in VB/C++ to return first 100 records? What is the SQL statement should be?

Thanks,

Sam

View 1 Replies View Related

Select One Record Only

Nov 14, 2001

Hi

Here is my example: I have the following table

ID Name Phone
--- ---- -----
1 John 1234567
1 John H.
2 Dave 9876543
2 Dave Smith

I want to select only one record of each ID, the output should be

ID Name Phone
--- ---- -----
1 John 1234567
2 Dave 9876543

It doesn't matter which record to select, but I need just a single complete record. I can't use select distinct ID because it will not show the other fieldnames.

Thanks

View 4 Replies View Related

Trying To Select Last Record...

Nov 8, 2004

I have a sql query that looks for values in a few different databases....

is there a way to select the last record in the table b/c I am pulling the hours worked on jobs and one person may have 3 job titles but i want it to show the balance of hours under the most recent job... Instead all the jobs are showing the same value even though only one of them had those hours under it. I think a way to get around this is to select the last value b/c that is under the job title most recently worked and they are in order by timesheets which can be ordered by date...any ideas?

View 2 Replies View Related

Select One Record

Sep 18, 2013

I have view with Patients name and Appointment table where I save those patients. How to create store procedure if I would like to select one patient record based on Patient_Id value?

View 3 Replies View Related

Using TOP To Select The 2nd Highest Record

Jun 19, 2007

Hai frendz,

I am having a table named Employee(int EID, float Salary)...
Now I want to select the highest salary in the table and the query is-

"select top 1 EID, Salary from Employee ORDER BY Salary DESC"

Now I need to write a query which selects the second highest salary.
So how to achieve this?..

thanx

View 6 Replies View Related

How To Lock Record On Select

May 29, 2008

hi
I want to lock the record on select query so that no other user can update this record, is it possible and i want to unlock record when use stop view this record.

View 1 Replies View Related

Select Only If There's A Same Record In The Table

Apr 26, 2005

i have two tables A and B. relation is one to many for A. i want to select from A only if there are more than two records of A in table B and also checking some condition in table B. if the question's not very clear please let me know.

View 1 Replies View Related

Select Date Record

Feb 18, 2006

    how to select record from the table where the data between a  range. example  between 2/16/2005 and 12/16/2005. the data record in the table formated like this ( 2/16/2005 11:44:38 PM). help me with some sql code, thanks

View 2 Replies View Related

How To Select First Record With Out Using Rowcount

Mar 20, 2002

Hi,
I need to select first record from a table.
This can be comfortably achieved by usibg set rowcount 1.
I need to do this with out using rowcount.

This is urgent.
Thanks
Krishna

View 2 Replies View Related

Select Next And Previous Record

Aug 28, 2001

Hi!

I need to select a spesific record using the recordkey and then select the previous and the next record as well. (which leaves me with a recordset containing three records)

Is this possible?

View 3 Replies View Related

How Can I Select Nth Record In A Table.

Nov 7, 2001

hi friends,

I am having a table with student marks in that i need to select a student who is the 5 th rank based on total marks obtained by the student.how can write sql for that.

name, totmarks
-----------------
kumar 145
ravi 300
jude 189
geeetha 320
rajesh 251
guru 190
ramesh 99
----------------------

i am having records like this.pl help me. thank u

regards
raj

View 1 Replies View Related

How To Select Record Only In One Table?

Feb 14, 2006

Hello, everyone:

I have two tables like:

Table A
IDCodeANumA
1D1289
2C4300
3C9409

Table B
IDCOdeBNumB
1D3266
2C4300
3C7101

How to find out the records that is in Table A not in Table B, and in Table B not in Table A? That means C4/300 should not be selected.

Thanks

ZYT

View 3 Replies View Related

How To Select One Record Many Times?

Sep 14, 2006

The developers of frond end ask to select only one row from one table, but many times, such as 10. That means the output has 10 rows and same.

Any suggestion will be appreciated.

ZYT

View 4 Replies View Related

Select Most Recent Record

Dec 21, 2006

Every hour we capture some values from our factory (position of pumps, valves, ...) in our sql server 2000 db.

Normally 1 record is added to the db.
00:00:00
01:00:00
02:00:00
...
21:00:00
22:00:00
23:00:00

All of these values are displayed in an Excel sheet. One sheet contains all the data from one month.

I noticed a problem last week when 2 records were added: first one at 19:00:00 and the second one at 19:00:01

We only want to keep the most recent record (19:00:01) in a situation like this but I can't seem to work out an SQL-statement :o

This is what we have know. It used to work fine untill we had 2 record being added instead of one.
SELECT TimeOfCapture, Value1, Value2, Value3
FROM FactoryTable
WHERE (MONTH(TimeOfCapture) = MONTH(GETDATE())) AND (YEAR(TimeOfCapture) = YEAR(GETDATE()))

View 1 Replies View Related

SELECT TOP 2 From Each Details Record

Apr 24, 2007

Hi everyone,

I am having a header table and details table and I want to display first 2 records against each header from details, whatever number of records are there in details against each header.


Example :
=======
Details table is as follows
HeaderID DetailsID
1 1
1 2
1 3
2 4
3 5
3 6
3 7
3 8


output should be:
TransDate SupplierName HeaderID DetailsID
1/1/2000 abc 1 1
1/1/2000 dsds 1 2
2/3/2003 fgd 2 4
2/4/2005 sdsd 3 5
1/1/2006 fgfdg 3 6


I am using the following query

SELECT H.TransDate, H.SupplierName, D.DetailsID FROM
Header H, Details D
WHERE H.HeaderID = D.DetailsID
AND D.DetailsID IN (SELECT TOP 2 DetailsID FROM Details WHERE HeaderID = H.HeaderID)


As I am dealing with very huge data it is taking very long time to execute.

Is there any better way to accomplish the task?

Thanks.

Riyaz

View 14 Replies View Related

How To Select Earliest Record

Mar 17, 2012

im trying to get the earliest record. data is below

note_id/ doc_received_date/ bankruptcy_date/ sp_recorded_date
2332/ 20090106<---- / 20081219/ 20090106
2332/ 20090323/ 20081219/ 20090323
2332/ 20090413/ 20081219/ 20090413
2332/ 20090507/ 20081219/ 20090507

because the bankruptcy_date date are all equal i would need to pull one record with the earliest date from the doc_received_date. The date with the arrow is the record i want. So basically i would like to show this result

note_id/ doc_received_date/ bankruptcy_date/ sp_recorded_date
2332 20090106 20081219 20090106

View 5 Replies View Related

Select Last Record By Group?

May 18, 2012

query to show last record/Partner or PartnerName.

select 'PURCHASE' as EntityName, d.PartnerName, h.*
from (
select MAX([TimeStamp]) [Data import], COUNT(1) [Numar de inregistrari], StartDate, EndDate, DistributorId
from DataImport.PurchaseHistory
group by DistributorId, StartDate, EndDate
) h
inner join Partner d on d.PartnerId = h.DistributorId
where d.Active = 1
order by DistributorId, StartDate desc, EndDate desc

View 4 Replies View Related

Select Max Record With A Condition

Sep 17, 2012

I am wondering how to select the Max date within a table where a timestamp is within 2 second of the other

IDTimestamp
1NULL
209/17/2012 11:04:32
309/17/2012 11:05:44
409/17/2012 11:05:45

So I need a query to return

IDTimestamp
409/17/2012 11:05:45

as 11:05:45 is the max of 09/17/2012 11:05:44 and 09/17/2012 11:05:45 and they are within 2 seconds of eachother.

View 6 Replies View Related

SQL Select Last Record Per Group

Jan 24, 2004

I'm looking for some sql syntax that will return the last entry per group in a secondary table. MEANING: have 2 tables, one with names and the other with visits. I need to be able to display all the patients with there last visits.

TABLE1 info
ID1 fname1 lname1 DOB1
ID2 fname2 lname2 DOB2
ID3 fname3 lname3 DOB3

TABLE2 info
ID1 Visit2
ID1 Visit3
ID1 Visit1
ID1 Visit4
ID2 Visit1
ID2 Visit2
ID3 Visit1

I need a view or SP to return the following:

ID1 fname1 lname1 dob1 visit4
ID2 fname2 lname2 dob2 visit2
ID3 fname3 lname3 dob3 visit1

It seems like it should be a smiple process, only I just can't get the syntax to work.... Any Help would be GREAT!
thx

View 2 Replies View Related

Select Nth Largest Record - How To?

Feb 3, 2004

How do i select first name of the lets say 6th highest salary of an employee?

is it use Select TOP statement?

p/s: I just want the 6th largest fname not the top 6. so it will only return one value.

Thank you in advance for your reply.

View 1 Replies View Related

Select Most Recent Record??

Apr 27, 2004

Hi,

I want to construct a query that would give the most recent record. Table data looks like -

F1F2F3 F4
20016395074/7/2004 15:40:55
23516395074/6/2004 9:31:54

All columns are strings as the data is obtained from text file. Column F3 can have same or different dates. In the above data select 1st record as it is the most recent.
If data is like -
F1F2F3 F4
20016395074/7/2004 15:40:55
23516395074/7/2004 19:31:54

Select the 2nd record.

How do I construct the SQL query?


Let me know.

View 1 Replies View Related

Select And Display Only One Record

Sep 18, 2013

I have view with Patients name and Appointment table where I save those patients. In form I have 2 comboboxes. For PatientComboBox source is store procedure based on Patient view. For PatientAppintmentComboBox I would like to create store procedure.

How to create store procedure to display only one PatierntName record in PatientAppointmentComboBox if Patient_Id selected from PatientComboBox exist or not exist in Appointment?

View 3 Replies View Related

Select One Record From Each Group

Jan 21, 2014

I have for example a table with columns name, surname, id, ..., weight, age. I need to choose from each age group (GROUP BY age) entire record of the person who has the greatest weight. How to construct such a query?

View 1 Replies View Related







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