Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Thursday, March 29, 2012

Getting a file name from Query Analyzer

Hi all,

im trying to write a stored procedure that will basically browse a folder and get me the first file that it sees. Is there any way that I can do this in TSQL or using CLR in C#? I was thinking something along the lines of using the dos dir command and triyng to pipe it into a variable, not sure how to go about doing this. Any suggestions?

dir /b ...gives me the bare file names, but it lists all the files in the folder, any way that i can just get the first file ( i dont really care what file).

create table #filelist
(
files varchar(500)
)


truncate table #filelist


insert #filelist
EXEC xp_cmdshell 'dir c:*.* /b'


select top 1 * from #filelist

|||

This might help out:

http://stevekass.com/blog/wp-content/Folders/sql/TextDriver.htm

You can use TOP 1 to get just one file name.

Steve Kass

Drew University

http://www.stevekass.com

YoungEngineer@.discussions.microsoft.com wrote:

> Hi all,

>

> im trying to write a stored procedure that will basically browse a

> folder and get me the first file that it sees. Is there any way that I

> can do this in TSQL or using CLR in C#? I was thinking something along

> the lines of using the dos dir command and triyng to pipe it into a

> variable, not sure how to go about doing this. Any suggestions?

>

> dir /b ...gives me the bare file names, but it lists all the files in

> the folder, any way that i can just get the first file ( i dont really

> care what file).

>

>

>

>

Friday, March 23, 2012

GETDATE() in a Function

Hi again.
I'm trying to write a user-defined function that accepts only one parameter, a date.
The function then calculates the amount of days elapsed between the specified date,
and the current system-date. I'm using DATEDIFF together with GETDATE() to try and
calculate the difference, but GETDATE() keeps on causing an error.
Can one use GETDATE() in a function?
I tried to call a stored procedure from the same function, and an error states that
only extended stored procedures or functions can be called from within the function...
Any way to bypass this?
Hi,
No, You cannot use getDate() inside a function. Non deterministic values can
not be used inside a function.(Te value og getdate changes every milli
second)
Solution1 :
The solution is Create view as select getDate() as currdate
and then use the view inside the function.
Thanks
Hari
MCDBA
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?
|||Another option is to add a datetime parameter to your
function and pass GetDate() as the value for the parameter
when calling the function.
-Sue
On Wed, 12 May 2004 02:21:04 -0700, "Rival"
<anonymous@.discussions.microsoft.com> wrote:

>Hi again.
>I'm trying to write a user-defined function that accepts only one parameter, a date.
>The function then calculates the amount of days elapsed between the specified date,
>and the current system-date. I'm using DATEDIFF together with GETDATE() to try and
>calculate the difference, but GETDATE() keeps on causing an error.
>Can one use GETDATE() in a function?
>I tried to call a stored procedure from the same function, and an error states that
>only extended stored procedures or functions can be called from within the function...
>Any way to bypass this?
|||Rival
Here is another approach
CREATE FUNCTION dbo.My_Fn(@.dt AS DATETIME)
RETURNS DATETIME
AS
BEGIN
RETURN @.dt
END
GO
SELECT dbo.My_Fn (GETDATE())
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?

GETDATE() in a Function

Hi again
I'm trying to write a user-defined function that accepts only one parameter, a date.
The function then calculates the amount of days elapsed between the specified date,
and the current system-date. I'm using DATEDIFF together with GETDATE() to try an
calculate the difference, but GETDATE() keeps on causing an error
Can one use GETDATE() in a function
I tried to call a stored procedure from the same function, and an error states that
only extended stored procedures or functions can be called from within the function..
Any way to bypass this?Hi,
No, You cannot use getDate() inside a function. Non deterministic values can
not be used inside a function.(Te value og getdate changes every milli
second)
Solution1 :
The solution is Create view as select getDate() as currdate
and then use the view inside the function.
Thanks
Hari
MCDBA
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?|||Another option is to add a datetime parameter to your
function and pass GetDate() as the value for the parameter
when calling the function.
-Sue
On Wed, 12 May 2004 02:21:04 -0700, "Rival"
<anonymous@.discussions.microsoft.com> wrote:
>Hi again.
>I'm trying to write a user-defined function that accepts only one parameter, a date.
>The function then calculates the amount of days elapsed between the specified date,
>and the current system-date. I'm using DATEDIFF together with GETDATE() to try and
>calculate the difference, but GETDATE() keeps on causing an error.
>Can one use GETDATE() in a function?
>I tried to call a stored procedure from the same function, and an error states that
>only extended stored procedures or functions can be called from within the function...
>Any way to bypass this?|||Rival
Here is another approach
CREATE FUNCTION dbo.My_Fn(@.dt AS DATETIME)
RETURNS DATETIME
AS
BEGIN
RETURN @.dt
END
GO
SELECT dbo.My_Fn (GETDATE())
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?

GETDATE() in a Function

Hi again.
I'm trying to write a user-defined function that accepts only one parameter,
a date.
The function then calculates the amount of days elapsed between the specifie
d date,
and the current system-date. I'm using DATEDIFF together with GETDATE() to t
ry and
calculate the difference, but GETDATE() keeps on causing an error.
Can one use GETDATE() in a function?
I tried to call a stored procedure from the same function, and an error stat
es that
only extended stored procedures or functions can be called from within the f
unction...
Any way to bypass this?Hi,
No, You cannot use getDate() inside a function. Non deterministic values can
not be used inside a function.(Te value og getdate changes every milli
second)
Solution1 :
The solution is Create view as select getDate() as currdate
and then use the view inside the function.
Thanks
Hari
MCDBA
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?|||Another option is to add a datetime parameter to your
function and pass GetDate() as the value for the parameter
when calling the function.
-Sue
On Wed, 12 May 2004 02:21:04 -0700, "Rival"
<anonymous@.discussions.microsoft.com> wrote:

>Hi again.
>I'm trying to write a user-defined function that accepts only one parameter
, a date.
>The function then calculates the amount of days elapsed between the specifi
ed date,
>and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
>calculate the difference, but GETDATE() keeps on causing an error.
>Can one use GETDATE() in a function?
>I tried to call a stored procedure from the same function, and an error sta
tes that
>only extended stored procedures or functions can be called from within the
function...
>Any way to bypass this?|||Rival
Here is another approach
CREATE FUNCTION dbo.My_Fn(@.dt AS DATETIME)
RETURNS DATETIME
AS
BEGIN
RETURN @.dt
END
GO
SELECT dbo.My_Fn (GETDATE())
"Rival" <anonymous@.discussions.microsoft.com> wrote in message
news:C3083184-B34B-4E01-A5B5-72ACBEB45C61@.microsoft.com...
> Hi again.
> I'm trying to write a user-defined function that accepts only one
parameter, a date.
> The function then calculates the amount of days elapsed between the
specified date,
> and the current system-date. I'm using DATEDIFF together with GETDATE() to
try and
> calculate the difference, but GETDATE() keeps on causing an error.
> Can one use GETDATE() in a function?
> I tried to call a stored procedure from the same function, and an error
states that
> only extended stored procedures or functions can be called from within the
function...
> Any way to bypass this?

Wednesday, March 21, 2012

GetChanges Update problem

I have the below C# routine which is working but now I need to write its newly randomized L_Rank values back up to the Sql Server. How can i do that in Button1_Click? DataTable 'dt' contains only two fields - L_ID and L_Rank. I have a stored procedure but I do not know how to call it in Button1_Click and pass the parameters it is looking for.

SP:
PROCEDURE RandomizeLinks
@.L_ID int,
@.L_Rank int
AS
UPDATE tblLinkInfo_OLD2 SET L_Rank = @.L_Rank
WHERE (L_ID = @.L_ID)

protected void Button1_Click(object sender, EventArgs e)
{
GetRandLinks();
DataTable dt = GetRandLinks();
int RowIncrement;
RowIncrement = 0;
System.Random myRandom = new System.Random();
foreach (DataRow row in dt.Rows)
{
int LinkRank = myRandom.Next(25, 250);
row["L_Rank"] = LinkRank;
RowIncrement++;
}

Is what I want to do possible - it seems easy but nothing I do works.

|||

Am I asking the question wrong - Can you use a DataTable to update a SQL Table and can it be done in a batch UPDATE as opposed to incrementing through every row?

|||

anyone?

Monday, March 19, 2012

Get uniqueness of a column from the system tables or information_schema

I'm trying to write a query which, from a given table name, will
produce a list of column names with an indicator as to whether it is
unique. By unique, I mean it a) is the column in a single-column
primary key, b) is the column in a single-column unique constraint, or
c) is the column in single-column unique index.
So, for this DDL,
-- CODE BEGINS
create table t1 (
c1 int not null primary key,
c2 int not null unique,
c3 int not null,
c4 int not null
)
create unique index ix1 on t1 (c3)
-- drop table t1
-- CODE ENDS
I'd like a query that will produce something like this output
c1 yes
c2 yes
c3 yes
c4 no
I've spent a few hours with sysobjects, sysindexes, sysconstraints, and
information_schema, but I'm getting nowhere. Anyone have any hints?
Thomas BergI forgot to say: I'm using SQL Server 2000 SP4.|||Hello, Thomas
This query returns the desired result:
SELECT name,
CASE WHEN EXISTS (
SELECT * FROM sysindexkeys k
INNER JOIN sysindexes i
ON k.id=i.id AND k.indid=i.indid
WHERE k.id=c.id AND k.colid=c.colid
AND INDEXPROPERTY(i.id,i.name,'IsUnique')=1
AND NOT EXISTS (
SELECT * FROM sysindexkeys k2
WHERE k.id=k2.id AND k.indid=k2.indid
AND k.keyno<>k2.keyno
)
) THEN 'yes' ELSE 'no' END AS IsUnique
FROM syscolumns c WHERE id=OBJECT_ID('t1')
Note that it's sufficient to search only for unique indexes, because
primary keys and unique keys are always enforced by creating a unique
index with the same name on the specified columns.
For a more thorough testing of the query, I added the following:
create unique index ix2 on t1 (c4,c3)
create index ix3 on t1 (c4)
Razvan|||tbergNoSpamPlease@.insight-system.co.jp a crit :
> I'm trying to write a query which, from a given table name, will
> produce a list of column names with an indicator as to whether it is
> unique. By unique, I mean it a) is the column in a single-column
> primary key, b) is the column in a single-column unique constraint, or
> c) is the column in single-column unique index.
> So, for this DDL,
> -- CODE BEGINS
> create table t1 (
> c1 int not null primary key,
> c2 int not null unique,
> c3 int not null,
> c4 int not null
> )
> create unique index ix1 on t1 (c3)
> -- drop table t1
> -- CODE ENDS
> I'd like a query that will produce something like this output
> c1 yes
> c2 yes
> c3 yes
> c4 no
> I've spent a few hours with sysobjects, sysindexes, sysconstraints, and
> information_schema, but I'm getting nowhere. Anyone have any hints?
> Thomas Berg
>
Here is a very general query wich give you all informations about
indexes with columns and uniqueness
SELECT
u.name AS IXD_SCHEMA_NAME,
o.name AS IXD_TABLE_NAME,
i.name AS IXD_INDEX_NAME,
CONSTRAINT_TYPE AS IXD_CONSTRAINT_TYPE,
CASE
WHEN i.indid = 0 THEN 'TABLE'
WHEN i.indid = 1 THEN 'CLUSTER'
WHEN i.indid BETWEEN 2 AND 254 THEN 'HEAP'
WHEN i.indid = 255 THEN 'TXTEIMAGE'
END AS IXD_INDEX_TYPE,
INDEXPROPERTY(o.id, i.name, 'IsUnique') AS IXD_IS_UNIQUE,
INDEXPROPERTY(o.id, i.name, 'IndexFillFactor') AS IXD_FILL_FACTOR,
c.name AS IXD_COL_NAME,
DATA_TYPE + '('+
CAST(COALESCE(CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION) AS
VARCHAR(16))
+ COALESCE(', '+CAST(NULLIF(NUMERIC_SCALE, 0) AS
VARCHAR(16)) , '') +')' AS IXD_COL_TYPE,
k.keyno AS IXD_COL_IDX_ORDER,
CASE
WHEN INDEXKEY_PROPERTY (o.id , i.indid , k.colid ,
N'isdescending' ) = 0 THEN 'ASC'
WHEN INDEXKEY_PROPERTY (o.id , i.indid , k.colid ,
N'isdescending' ) = 1 THEN 'DESC'
WHEN INDEXKEY_PROPERTY (o.id , i.indid , k.colid ,
N'isdescending' ) IS NULL THEN ''
END AS IXD_COL_DATA_ORDER,
INDEXPROPERTY(o.id, i.name, 'IsRowLockDisallowed') AS
IXD_ROW_LOCK_DISALLOWED,
INDEXPROPERTY(o.id, i.name, 'IsPageLockDisallowed') AS
IXD_PAGE_LOCK_DISALLOWED
FROM dbo.sysindexes i
INNER JOIN dbo.sysobjects o
ON i.id = o.id
INNER JOIN dbo.sysusers u
ON o.uid = u.uid
INNER JOIN dbo.sysindexkeys k
ON o.id = k.id
and i.indid = k.indid
INNER JOIN dbo.syscolumns c
ON k.colid = c.colid
and o.id = c.id
INNER JOIN INFORMATION_SCHEMA.COLUMNS ISC
ON u.name = ISC.TABLE_SCHEMA
AND o.name = ISC.TABLE_NAME
AND c.name = ISC.COLUMN_NAME
LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TCT
ON u.name = TCT.CONSTRAINT_SCHEMA
AND i.name = TCT.CONSTRAINT_NAME
WHERE i.status & 64 <> 64 -- sauf les index "stat"
A +
Frdric BROUARD, MVP SQL Server, expert bases de donnes et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modlisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************|||You guys are brilliant. Thanks.

Monday, March 12, 2012

get todays date and a certain time

Hi Everyone,

I am trying to write something to give me back all the data for a
sertain time range for today.
So for example: I need to get all records where change_date is <= today
2pm and today at 8pm.
I know i can get just the date for today by using
CONVERT(CHAR(10),getdate(),102) but can i add a time range to that?

Thanks in advance,
AnnaYou can use DATEADD, for example:

SELECT DATEADD(hour,14,CONVERT(CHAR(10),getdate(),102))

Razvan

AKorsakova@.gmail.com wrote:

Quote:

Originally Posted by

Hi Everyone,
>
I am trying to write something to give me back all the data for a
sertain time range for today.
So for example: I need to get all records where change_date is <= today
2pm and today at 8pm.
I know i can get just the date for today by using
CONVERT(CHAR(10),getdate(),102) but can i add a time range to that?
>
Thanks in advance,
Anna

|||On 27 Sep 2006 11:36:59 -0700, AKorsakova@.gmail.com wrote:

Quote:

Originally Posted by

>Hi Everyone,
>
>I am trying to write something to give me back all the data for a
>sertain time range for today.
>So for example: I need to get all records where change_date is <= today
>2pm and today at 8pm.
>I know i can get just the date for today by using
>CONVERT(CHAR(10),getdate(),102) but can i add a time range to that?


Hi Anna,

Use either

CONVERT(datetime, CONVERT(CHAR(10), getdate(), 126) + 'T14:00:00')

or

DATEADD(day, DATEDIFF(day, 0, getdate()), '14:00:00')

to get current date with a time of 2PM.

--
Hugo Kornelis, SQL Server MVP

Sunday, February 26, 2012

Get rows fields as xml name value pairs

Hi,
I'm trying to write a procedure to return the data from a query as xml
in the following format:
<root>
<row>
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
</row>
<row>
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
</row>
<row>
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
<Field Name="[FieldName]" Value="[FieldValue]" />
</row>
</root>
so basically i need to turn the fields of a row into new rows?
I want to send them to a waiting app for deserialization into an
object but want the object to able to deserialize the data whatever it
is.
Any ideas?
Thanks,
George
Your best bet is probably to use an AUTO mode query and then apply an XSLT
transform.
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
www.microsoft.com/mspress/books/6137.asp
"george" <8eu1ukg02@.sneakemail.com> wrote in message
news:d90f7cf1.0405270433.27d2fdbd@.posting.google.c om...
> Hi,
> I'm trying to write a procedure to return the data from a query as xml
> in the following format:
> <root>
> <row>
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> </row>
> <row>
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> </row>
> <row>
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> <Field Name="[FieldName]" Value="[FieldValue]" />
> </row>
> </root>
> so basically i need to turn the fields of a row into new rows?
> I want to send them to a waiting app for deserialization into an
> object but want the object to able to deserialize the data whatever it
> is.
> Any ideas?
> Thanks,
> George

Friday, February 24, 2012

get record with latest date

if there are 2 records with different date

how to write query for --> get record with latest date

Hi,

use Order By clause.

For example,

Select top 1 * from YourTable Order By YourDateFieldName Desc

|||

Use something like this:

SELECT TOP 1 *
FROM MyTable
ORDER BY DateField DESC

Regards,
Martin

|||

Here is an example based on the NorthWinds database:

Select TOP 1 *from OrdersOrder by OrderDateDesc
|||

Here is another way to do it:

select *
from MyTable
where timestampfield = (select max(timestampfield)
from MyTable)

get path of the database file using a query

Hi guys,
all i want to do is , get the path of the location of my database and log
file using a query of a command i could write down in the query anylyser.
Thanks
Sameer MuzammilTry using:
sp_helpfile
--
HTH, Jens Suessmeyer.
--
http://www.sqlserver2005.de
--
"sameer" <sameer@.discussions.microsoft.com> schrieb im Newsbeitrag
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil|||Hi,
You could also use
sp_helpdb <dbname>
Thanks
Hari
SQL Server MVP
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil|||Hi Sameer,
You can extract info from sysdatabses system table. As Jens replied you
sp_helpfile this system stored procdure also make use of this system table.
select name,filename from sysdatabases
go
Thanks
Syed Zulfiqar
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil

get path of the database file using a query

Hi guys,
all i want to do is , get the path of the location of my database and log
file using a query of a command i could write down in the query anylyser.
Thanks
Sameer Muzammil
Try using:
sp_helpfile
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"sameer" <sameer@.discussions.microsoft.com> schrieb im Newsbeitrag
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil
|||Hi,
You could also use
sp_helpdb <dbname>
Thanks
Hari
SQL Server MVP
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil
|||Hi Sameer,
You can extract info from sysdatabses system table. As Jens replied you
sp_helpfile this system stored procdure also make use of this system table.
select name,filename from sysdatabases
go
Thanks
Syed Zulfiqar
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil

get path of the database file using a query

Hi guys,
all i want to do is , get the path of the location of my database and log
file using a query of a command i could write down in the query anylyser.
Thanks
Sameer MuzammilTry using:
sp_helpfile
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"sameer" <sameer@.discussions.microsoft.com> schrieb im Newsbeitrag
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil|||Hi,
You could also use
sp_helpdb <dbname>
Thanks
Hari
SQL Server MVP
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil|||Hi Sameer,
You can extract info from sysdatabses system table. As Jens replied you
sp_helpfile this system stored procdure also make use of this system table.
select name,filename from sysdatabases
go
Thanks
Syed Zulfiqar
"sameer" <sameer@.discussions.microsoft.com> wrote in message
news:25DDB26C-501D-4DCA-979F-3587514744D0@.microsoft.com...
> Hi guys,
> all i want to do is , get the path of the location of my database and log
> file using a query of a command i could write down in the query anylyser.
> Thanks
> Sameer Muzammil

Sunday, February 19, 2012

Get only Max of each distinct?

Hello,

I have a table

ItemID Version

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0
15 2.1

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?

Like this:

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1

Any help would be appreciated.

Thankssunilkes@.gmail.com wrote:

Quote:

Originally Posted by

I have a table
>
ItemID Version
>
12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0


I assume 5.0 is a typo for 2.0

Quote:

Originally Posted by

15 2.1
>
How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?
>
Like this:
>
ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1


This smells like homework. Look up MAX() and GROUP BY.|||On Nov 7, 10:10 am, Ed Murphy <emurph...@.socal.rr.comwrote:

Quote:

Originally Posted by

sunil...@.gmail.com wrote:

Quote:

Originally Posted by

I have a table


>

Quote:

Originally Posted by

ItemID Version


>

Quote:

Originally Posted by

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0


>
I assume 5.0 is a typo for 2.0
>


Got it, actually it was pretty simple, was trying it incorrectly
earlier !

SELECT MAX(Version_Number) AS Maxim, ItemId
FROM tblItems
GROUP BY ItemId

Thanks

Quote:

Originally Posted by

Quote:

Originally Posted by

15 2.1


Quote:

Originally Posted by

>

Quote:

Originally Posted by

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?


>

Quote:

Originally Posted by

Like this:


>

Quote:

Originally Posted by

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1


>
This smells like homework. Look up MAX() and GROUP BY.