Showing posts with label alli. Show all posts
Showing posts with label alli. Show all posts

Friday, March 9, 2012

list of months between two date

hi all

i need a query which will give the list of all the months between two given dates

I am not sure this works in all query languages, but in T-SQL you can use the following:

SELECT DATEDIFF(m, GetDate(), '12/25/2006')

This gives you the number of months between today and Christmas. Running that query in SQL will return "1" (if you ran it today anyway). The structure for the command is:

DATEDIFF(datepart, startdate, enddate)

For the datepart, you use "m" to indicate you want the number of months. You could also use "d" for days or "y" for years.

Hope this helps.

-Jacob

|||

no jacob i need list of months between two dates

forexample

input:

startdate:1/1/2006

enddate:1/12/2006

output:

jan-2006

feb-2006

.....

......

dec-2006

|||

Funny, rather work on other bugs right now than my own heehee, if anyone knows how to print a barcode from MS Reporting Services let me know.
I have a thread about ithere.

But here's some code for vmssanthosh:

DECLARE @.date1datetime, @.date2datetime, @.totalMonthsint, @.counterintSET @.date1 ='01/01/2006'SET @.date2 ='01/01/2007'--'02/02/2007'SET @.totalMonths =DATEDIFF(m, @.date1, @.date2)if(@.totalMonths < 0)SELECT'Second date parameter is prior to the first date parameter'if(@.totalMonths =0)SELECT'Same month'elseBEGINcreate table #temp_months(nameOfMonthvarchar(9))SET @.counter = 0WHILE @.counter < @.totalMonthsBEGININSERT INTO #temp_months (nameOfMonth)VALUES (DATENAME(month, @.date1))SET @.counter = @.counter + 1SET @.date1 =DATEADD(Month, 1, @.date1)ENDSELECT *FROM #temp_monthsEND
|||

For the format you specified, change the INSERT statement to this:

INSERT INTO #temp_months (nameOfMonth)VALUES (LEFT(DATENAME(month, @.date1),3) +'-' +DATENAME(year, @.date1))

Friday, February 24, 2012

List of accessible databases on a server

Hi All
I once saw this app that allowed you to pick a SQL server and provided your
signon details; it then displayeda list of DBs on that server which you had
access to with the provided signon.
Does anybody know how they did this? How they got the list of databases off
the server?
ThanksHi
EXEC sp_MSForEachDB "use ? select '?' as dbname, name as username from
sysusers where islogin = 1 and hasdbaccess = 1"
"Chan" <Chan@.discussions.microsoft.com> wrote in message
news:B87B3DDC-4F51-4810-959A-96CFB27E93BD@.microsoft.com...
> Hi All
> I once saw this app that allowed you to pick a SQL server and provided
> your
> signon details; it then displayeda list of DBs on that server which you
> had
> access to with the provided signon.
> Does anybody know how they did this? How they got the list of databases
> off
> the server?
> Thanks|||You could start with:
SELECT name FROM master..sysdatabases
"Chan" <Chan@.discussions.microsoft.com> wrote in message
news:B87B3DDC-4F51-4810-959A-96CFB27E93BD@.microsoft.com...
> Hi All
> I once saw this app that allowed you to pick a SQL server and provided
> your
> signon details; it then displayeda list of DBs on that server which you
> had
> access to with the provided signon.
> Does anybody know how they did this? How they got the list of databases
> off
> the server?
> Thanks

List databases and size of an instance or sql server

Hi all
I looking the way to list the all the databases in a server and get other
properites such the size of each one.
The list of the databases of are in the master databaes, select name from
sysdatabases, but the other properties are inside on each databes (size,
last backup...) How i can use the select like a variable to connect to the
rest of the databases in the server o instance?
Best Regards
FernandoHi,
Execute the below system procedure from query analyzer:-
sp_helpdb
Thanks
Hari
SQL Server mvp
"Nano" <Nano@.discussions.microsoft.com> wrote in message
news:86D15A09-972A-4D12-8893-D3FE79C4FCFC@.microsoft.com...
> Hi all
> I looking the way to list the all the databases in a server and get other
> properites such the size of each one.
> The list of the databases of are in the master databaes, select name from
> sysdatabases, but the other properties are inside on each databes (size,
> last backup...) How i can use the select like a variable to connect to the
> rest of the databases in the server o instance?
> Best Regards
> Fernando