Showing posts with label written. Show all posts
Showing posts with label written. Show all posts

Saturday, February 25, 2012

Complex Order By Logic

I apologize if this is not the appropriate forum for this question.

I've

written a searchable database-driven application in classic ASP and

vbscript with a SQL Server backend. What I need to do is this: order

the results of a query so that if the first "order by" field is null to

order that entry based on the second "order by" field.

The

application I am writing is a database of books, and my client wants

the results to be ordered by Author, unless there is no Author, in

which case he wants that entry ordered by book title. Here is an

example of how he wants the books sorted:

Adamson, Jan - Book X
Bible, The
Wilson, Jonathan - Book Y

I

hope I've explained the scenario correctly. What's the best way to

write a SQL statement that will yield the ordering criteria described

above? Also, is there any way to get "Order by" to ignore articles like

"A" and "The?"

I personally hate this idea, as it would be annoying to scan through. I would put no authors at the end or beginning as 'No Author.'

You can use coalesce to do this:

create table authorTitle
(
author varchar(20),
title varchar(20)
)
insert into authorTitle
select 'Adamson, Jan','Book X'
union
select NULL, 'Bible, The'
union
select 'Wilson, Jonathan','Book Y'
go

select *
from authorTitle
order by coalesce(author,'') + coalesce(title,'')

author title
-- --
Adamson, Jan Book X
NULL Bible, The
Wilson, Jonathan Book Y

You will probably going to want to add this as a computed column, and likely index it to get this to get this to perform well if you have lots of books in the database.

|||Thank you! That did the trick.

Sunday, February 19, 2012

complete bkup & log size

Hi ,
does a complete backup automatically reduce a log file size by removing
the inactive entries and those already written to the database ?
i have created a completed database backup on a weeklt basis but it still
seem that the log file is quite huge around 11 GB ?
could anyone kindly advise how i can approach this backup issue ?
tks & rdgsBackups do not reduce the size of any files. You must issue regular log
backups in addition to FULL backups if your database recover model is set to
FULL. or Bulk Logged. If you don't wish to do log backups you should change
it to simple mode. To shrink the file once you have fixed the process you
can use DBCC SHRINKFILE.
--
Andrew J. Kelly SQL MVP
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:4BF03439-3AA2-4B9C-9E90-D9C046F88A29@.microsoft.com...
> Hi ,
> does a complete backup automatically reduce a log file size by removing
> the inactive entries and those already written to the database ?
> i have created a completed database backup on a weeklt basis but it still
> seem that the log file is quite huge around 11 GB ?
> could anyone kindly advise how i can approach this backup issue ?
> tks & rdgs

complete bkup & log size

Hi ,
does a complete backup automatically reduce a log file size by removing
the inactive entries and those already written to the database ?
i have created a completed database backup on a weeklt basis but it still
seem that the log file is quite huge around 11 GB ?
could anyone kindly advise how i can approach this backup issue ?
tks & rdgsBackups do not reduce the size of any files. You must issue regular log
backups in addition to FULL backups if your database recover model is set to
FULL. or Bulk Logged. If you don't wish to do log backups you should change
it to simple mode. To shrink the file once you have fixed the process you
can use DBCC SHRINKFILE.
Andrew J. Kelly SQL MVP
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:4BF03439-3AA2-4B9C-9E90-D9C046F88A29@.microsoft.com...
> Hi ,
> does a complete backup automatically reduce a log file size by removing
> the inactive entries and those already written to the database ?
> i have created a completed database backup on a weeklt basis but it still
> seem that the log file is quite huge around 11 GB ?
> could anyone kindly advise how i can approach this backup issue ?
> tks & rdgs

complete bkup & log size

Hi ,
does a complete backup automatically reduce a log file size by removing
the inactive entries and those already written to the database ?
i have created a completed database backup on a weeklt basis but it still
seem that the log file is quite huge around 11 GB ?
could anyone kindly advise how i can approach this backup issue ?
tks & rdgs
Backups do not reduce the size of any files. You must issue regular log
backups in addition to FULL backups if your database recover model is set to
FULL. or Bulk Logged. If you don't wish to do log backups you should change
it to simple mode. To shrink the file once you have fixed the process you
can use DBCC SHRINKFILE.
Andrew J. Kelly SQL MVP
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:4BF03439-3AA2-4B9C-9E90-D9C046F88A29@.microsoft.com...
> Hi ,
> does a complete backup automatically reduce a log file size by removing
> the inactive entries and those already written to the database ?
> i have created a completed database backup on a weeklt basis but it still
> seem that the log file is quite huge around 11 GB ?
> could anyone kindly advise how i can approach this backup issue ?
> tks & rdgs