Friday, March 30, 2012
Print ER diagram for a database in SQL Server
I am a newbie to SQL Server so please bear with me if I happen to ask a
stupid question.
I am trying to print the ER diagram for our database in SQL server. In
Enterprise Manager we have an option to create the ER Diagram and then to
print it. But the problem is it prints into several pages.
I want in to print on a large paper so I could stick it to my wall. We have
a 36'x36' plotter that could print huge diagrams.
Do I have to convert it into PDF to print in on page.
Please give me some ideas.
thanks,
UdayUday,
right-click on the white background on the database
diagram and select Page Setup. You can select different
page sizes and scale ratios on this form.
Rgds,
Paul Ibison (SQL Server MVP)|||You might also want to create "subject" areas by creating several individual
diagrams for the functional areas of the database instead of the entire
thing in one.
Sincerely,
Anthony Thomas
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:02af01c4dc3c$1ce5b0a0$a601280a@.phx.gbl...
Uday,
right-click on the white background on the database
diagram and select Page Setup. You can select different
page sizes and scale ratios on this form.
Rgds,
Paul Ibison (SQL Server MVP)
Saturday, February 25, 2012
previous month on first day
Newbie question. I am using a query that pulls month-to-date data that has the following where clause:
WHERE (MONTH(datefield) = MONTH(GETDATE())) AND (YEAR(datefield) = YEAR(GETDATE()))
this works just fine but what I would like for it to do is give me the previous month of data if the if it's
the first day of the month and then any other day give me month to date. Is this possible?
Thanks in advance,
Marco
Could you just use GETDATE()-1?
Code Snippet
WHERE (MONTH(datefield) = MONTH(GETDATE()-1)) AND (YEAR(datefield) = YEAR(GETDATE()-1))
HTH!
|||I'm sorry, I should have added that I want to accomplish this without having to modify the query every month.
|||Sorry, i don't understand. Why would you have to modify the query every month?
|||Well, throughout the entire month I use WHERE (MONTH(datefield) = MONTH(GETDATE())) AND (YEAR(datefield) = YEAR(GETDATE())) to get the month to date data and then when the new month starts Ihave to change it to WHERE (MONTH(datefield) = MONTH(GETDATE()-1)) AND (YEAR(datefield) = YEAR(GETDATE())) to get the previous month and then change it back to continue the month-to-date data.
|||But as you're only matching on month and year, you won't have to change it. GETDATE()-1 will take one day off the date, and so it just means that on the 1st day of the month, it will use the last day of the last month whereas any other day within that month, the month and year values are the same.
Test it out:
Code Snippet
declare @.date datetime
set @.date = '1 nov 2007'
select month(@.date-1), year(@.date-1)
declare @.date datetime
set @.date = '20 nov 2007'
select month(@.date-1), year(@.date-1)
|||
Code Snippet
SELECT DATEADD(m,-1,DATEADD(m, DATEDIFF(m, 0, '8/29/07'), 0))
Lee Everest
Sr. Consultant - Sogeti USA LLC
www.texas2oo.com/sqlblog
|||
You can combine the 2 WHERE clause like this :
select datefield,month(datefield) from dbo.datefieldtable
WHERE (
MONTH(datefield)=
case when DATEPART(day, GETDATE())=1 then MONTH(GETDATE()-1)
else MONTH(GETDATE()) end )
AND
YEAR(datefield) = YEAR(GETDATE())
--with DATEPART(day, GETDATE())=1 you can obtain the first day of month
You have to see the performance!
|||here it is,
Code Snippet
where
datefield >= case when day(getdate()) = 1 then
cast(convert(varchar,dateadd(mm,-1,getdate()),101) as datetime)
else
cast(convert(varchar,dateadd(dd,1-day(getdate()),getdate()),101) as datetime)
end
and
datefield < case when day(getdate()) = 1 then
cast(convert(varchar,getdate(),101) as datetime)
else
cast(convert(varchar,getdate()+1,101) as datetime)
end
|||Perhaps the range can be obtained by something like:
Code Snippet
declare @.testDates table (dt datetime)
insert into @.testDates
select '7/20/7' union all
select '7/31/7' union all
select '8/1/7' union all
select '8/2/7' union all
select '8/5/7' union all
select '8/31/7' union all
select '9/1/7' union all
select '9/2/7'
--select * from @.testDates
select dt,
dateadd(mm, datediff(mm, 0, dt-1), 0) as rangeLow,
dateadd(mm, datediff(mm, 0, dt-1) + 1, 0) as rangeHi,
dateadd(mm, datediff(mm, 0, dt-1) + 1, 0)-1 as monthEnd
from @.testDates
/*
dt rangeLow rangeHi monthEnd
--
2007-07-20 2007-07-01 2007-08-01 2007-07-31
2007-07-31 2007-07-01 2007-08-01 2007-07-31
2007-08-01 2007-07-01 2007-08-01 2007-07-31
2007-08-02 2007-08-01 2007-09-01 2007-08-31
2007-08-05 2007-08-01 2007-09-01 2007-08-31
2007-08-31 2007-08-01 2007-09-01 2007-08-31
2007-09-01 2007-08-01 2007-09-01 2007-08-31
2007-09-02 2007-09-01 2007-10-01 2007-09-30
*/
Got it. Thank you all.
Previous Function - Help
previous function works. The documentation in the online books is a little
sketchy. Does someone have a detailed example? If not, could someone point
me to more detailed documentation on this function?
Thanks,
RickThe documentation about the Previous() function is actually incorrect
because it describes multiple parameters. The Previous function only has one
argument which is an expression and you can use Previous() only in a list or
a table.
Example:
=Previous(Fields!A.Value)
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Rick" <Rick@.discussions.microsoft.com> wrote in message
news:A47E8613-9078-4610-A528-FC5923197318@.microsoft.com...
> Newbie question. I have searched the posts and have found a few that say
> the
> previous function works. The documentation in the online books is a
> little
> sketchy. Does someone have a detailed example? If not, could someone
> point
> me to more detailed documentation on this function?
> Thanks,
> Rick|||Thanks Robert. Works like a champ.
"Robert Bruckner [MSFT]" wrote:
> The documentation about the Previous() function is actually incorrect
> because it describes multiple parameters. The Previous function only has one
> argument which is an expression and you can use Previous() only in a list or
> a table.
> Example:
> =Previous(Fields!A.Value)
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Rick" <Rick@.discussions.microsoft.com> wrote in message
> news:A47E8613-9078-4610-A528-FC5923197318@.microsoft.com...
> > Newbie question. I have searched the posts and have found a few that say
> > the
> > previous function works. The documentation in the online books is a
> > little
> > sketchy. Does someone have a detailed example? If not, could someone
> > point
> > me to more detailed documentation on this function?
> >
> > Thanks,
> > Rick
>
>
Previous day query
I am a newbie on SQL qieries and I am trying to run a query on a date/time filed to get yesterdays data.
Here is my test query ran from SQL analyzer:
select * from mvs_store_all_data_time_change where mvs_creation_date = {fn NOW() }
The error I am getting is:
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
I assume it is to do with the format of this field I am trying to query and may need to be converted?
Any help will be much appreciated.
Cheers,
Riaan.Riaan,
Try
select * from mvs_store_all_data_time_change
where mvs_creation_date > (getdate()-1)|||try this one
select * from <table> where DATEPART(dd, <date_column>)=DATEPART(dd, getdate()-1)
<date_column>-where your date is saved
Explanation-let it be 03/08/2006 today,then DATEPART(dd, getdate()-1)
returns 02.and u can get the data of the previous day.
Regards,
Lipsa|||Try this one
select * from <table> where DATEPART(dd, <date_column>)=DATEPART(dd, getdate()-1)
<date_column>-your column name in database where u insert dates
Explanation-suppose its 03/08/2006 today.so ,DATEPART(dd, getdate()-1)will return 02.and u can do the comarison and get the data of previous day. :)
Regards,
Lipsa :)|||Hi There.
Ok, I have tried your suggestion, but get the following error:
"Syntax error converting datetime from character string."
Any further ideas :). Cheers, Riaan.|||Hi Phil. Ok I treid your suggestion, but get the following error "Syntax error converting datetime from character string.". Any more ideas :).
Cheers, Riaan.|||
Quote:
Originally Posted by Riaan
Hi Phil. Ok I treid your suggestion, but get the following error "Syntax error converting datetime from character string.". Any more ideas :).
Cheers, Riaan.
Ho Riaan,
try this one...
select * from mvs_store_all_data_time_change
where convert(char,mvs_creation_date,102) = convert(char,getdate()-1,102)
regards,
Pankaj Bhatnagar|||
Quote:
Originally Posted by bhatnagarp
Ho Riaan,
try this one...
select * from mvs_store_all_data_time_change
where convert(char,mvs_creation_date,102) = convert(char,getdate()-1,102)
regards,
Pankaj Bhatnagar
Hi Pankaj
Ok, I tried your suggestion and now I am not getting the error message, but no data is returned? Is this not a case of converting this field (which is a integer, to a string and then cast it as a datetime format?). If so, can you maybe help with the syntax of such a query? ALso can I do it from a view, where I am running this from, as I am also not sure where to enter it in the view?. Hope you can help.
Cheers,
Riaan.|||Hi Pankaj
Ok, I tried your suggestion and now I am not getting the error message, but no data is returned? Is this not a case of converting this field (which is a integer, to a string and then cast it as a datetime format?). If so, can you maybe help with the syntax of such a query? ALso can I do it from a view, where I am running this from, as I am also not sure where to enter it in the view?. Hope you can help.
Cheers,
Riaan.