Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Friday, March 30, 2012

Print ER diagram for a database in SQL Server

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)
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)
sql

Friday, March 23, 2012

Primary Key using Select Into

Is it possible for me to define a Primary Key on a table using a Select Into
statement? If so could someone give me an example of how to do this?> Is it possible for me to define a Primary Key on a table using a Select
> Into
> statement? If so could someone give me an example of how to do this?
SELECT ...
INTO dbo.NewTableName
FROM dbo.OldTableName
GO
ALTER TABLE dbo.NewTableName ADD PRIMARY KEY(ColumnName)
Tom
http://kbupdate.com/sql

Tuesday, March 20, 2012

Primary key and identity fields information got lost by "Import Da

Hi all!
I want to import data from Sql Server 2000 into Sql Server 2005.
When i select "Import Data" in 2005 and import tables directly from the 2000
Data Source, the primary keys and the identity fields information is lost in
2005.
Who knows why?
Best regards
Ulrich Schumacher
urlich
How about BACKUP /RESTORE commands
Or you can create a linked server to SQL Server 2000 and run SELECT * INTO
Schema.Mytable FROM SQL2K.Database.DBO.Table it ON SQL Server 2005
"ulrich schumacher" <ulrichschumacher@.discussions.microsoft.com> wrote in
message news:D20F7B7B-5C85-441B-AFE5-14191B3DF6CA@.microsoft.com...
> Hi all!
> I want to import data from Sql Server 2000 into Sql Server 2005.
> When i select "Import Data" in 2005 and import tables directly from the
> 2000
> Data Source, the primary keys and the identity fields information is lost
> in
> 2005.
> Who knows why?
> Best regards
> Ulrich Schumacher
>

Primary key and identity fields information got lost by "Import Da

Hi all!
I want to import data from Sql Server 2000 into Sql Server 2005.
When i select "Import Data" in 2005 and import tables directly from the 2000
Data Source, the primary keys and the identity fields information is lost in
2005.
Who knows why?
Best regards
Ulrich Schumacherurlich
How about BACKUP /RESTORE commands
Or you can create a linked server to SQL Server 2000 and run SELECT * INTO
Schema.Mytable FROM SQL2K.Database.DBO.Table it ON SQL Server 2005
"ulrich schumacher" <ulrichschumacher@.discussions.microsoft.com> wrote in
message news:D20F7B7B-5C85-441B-AFE5-14191B3DF6CA@.microsoft.com...
> Hi all!
> I want to import data from Sql Server 2000 into Sql Server 2005.
> When i select "Import Data" in 2005 and import tables directly from the
> 2000
> Data Source, the primary keys and the identity fields information is lost
> in
> 2005.
> Who knows why?
> Best regards
> Ulrich Schumacher
>

Primary key and identity fields information got lost by "Import Da

Hi all!
I want to import data from Sql Server 2000 into Sql Server 2005.
When i select "Import Data" in 2005 and import tables directly from the 2000
Data Source, the primary keys and the identity fields information is lost in
2005.
Who knows why?
Best regards
Ulrich Schumacherurlich
How about BACKUP /RESTORE commands
Or you can create a linked server to SQL Server 2000 and run SELECT * INTO
Schema.Mytable FROM SQL2K.Database.DBO.Table it ON SQL Server 2005
"ulrich schumacher" <ulrichschumacher@.discussions.microsoft.com> wrote in
message news:D20F7B7B-5C85-441B-AFE5-14191B3DF6CA@.microsoft.com...
> Hi all!
> I want to import data from Sql Server 2000 into Sql Server 2005.
> When i select "Import Data" in 2005 and import tables directly from the
> 2000
> Data Source, the primary keys and the identity fields information is lost
> in
> 2005.
> Who knows why?
> Best regards
> Ulrich Schumacher
>

Wednesday, March 7, 2012

Price of using multiple databases in SELECT statements

Hi,

We are discussing possible implementation for sql2005 database(s). This database will serve one web portal. Part of data will get into it by hand, and part will be replicated from internal system.

Some of us are for creating two separate databases, since there are two separate datasources. One, automatic, will change very little over time and requires almost no maintenance. Other datasource will be manual input. Tables and procedures related to this part will change over time.

Some of us are for creating single database, since it will serve one web site. More important this group is concerned about performance issues since almost every select will require join between tables that would be stored in two separate databases. Do these issues exist?

Can you share some insights, comments, links about this?

Hi,

We are using multiple databases in our many application, and have not found an excuse so far that we should terminate that practice. Most of our modules gather data from different databases and operate on them. I think a little performance overhead is there, which can be ignored.

As every approach has its pros and cons. But we think that this segregation provides us opportunity to

- encapsulate different type of data in separate locations,

- which can be backed up easily,

- can be distributed at different locations,

- due to lesser size data would be fetched rather fast,

- unorganized data could be separaterd.


Whats your take on it?

|||

We too use multiple databases (on the same server, of course) and join across them -- there is no performance penalty that we've ever seen.

In our situation, we have a vendor package around which we've written an extended application. The vendor package uses one database and our extension uses another, but the two are intimately linked and we have views in the extention database pointing back to the vendor packages database (making it very easy to code. I recommend that you too use views to make it appear as though it's one big database.

previous row

Hi,
I am trying to do a query where I want to show not only the relevant results
but the previous line as well.
eg.
select *
where msg='crash'
I have a rowno in there but I am pretty new to this stuff so not real sure.
Thanks in advance
TimPerhaps you can give us some DDL and show us what you want to retrieve when
you issue am smaple command
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Timmeah" <timoth@.optushome.com.au> schrieb im Newsbeitrag
news:42916000$0$4656$afc38c87@.news.optusnet.com.au...
> Hi,
> I am trying to do a query where I want to show not only the relevant
> results
> but the previous line as well.
> eg.
> select *
> where msg='crash'
> I have a rowno in there but I am pretty new to this stuff so not real
> sure.
> Thanks in advance
> Tim
>|||ok, as I say I am pretty new to this so excuse any misunderstandings
columns: date msg type detail
rowno
11/5/06 info prog running
1
11/5/06 error prog crash
2
I basically want to be able to show the rowno previous to the prog crash
So I have,
Select *
from TABLENAME
where detail ='prog crash'
but I not sure how to do the next bit to retrieve the previous row.
thanks in advance
Tim
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:elnUUV1XFHA.1404@.TK2MSFTNGP09.phx.gbl...
> Perhaps you can give us some DDL and show us what you want to retrieve
when
> you issue am smaple command
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Timmeah" <timoth@.optushome.com.au> schrieb im Newsbeitrag
> news:42916000$0$4656$afc38c87@.news.optusnet.com.au...
>|||That would be one solution for that:
Select TOP 2 * from TABLENAME
Where Rowno <=
(
Select TOP 1 *
from TABLENAME
where detail ='prog crash'
order by rowno
)
Order by row no desc
I added the order by rowno if the detailcolumn is not precise enough,
perhaps mor ethan one coumn would fit that condition, saythose with 4 and
105, should then the rows 3 AND 104 be returned, or is the detail column
that precise only to return one row at a time ?
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Timmeah" <timoth@.optushome.com.au> schrieb im Newsbeitrag
news:42916a43$0$10304$afc38c87@.news.optusnet.com.au...
> ok, as I say I am pretty new to this so excuse any misunderstandings
> columns: date msg type detail
> rowno
> 11/5/06 info prog running
> 1
> 11/5/06 error prog crash
> 2
>
> I basically want to be able to show the rowno previous to the prog crash
> So I have,
> Select *
> from TABLENAME
> where detail ='prog crash'
> but I not sure how to do the next bit to retrieve the previous row.
> thanks in advance
> Tim
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in
> message news:elnUUV1XFHA.1404@.TK2MSFTNGP09.phx.gbl...
> when
>|||yes would return 3 and 104 as well.
that query gives an error
'Only one expression can be specified in the select list when the subquery
is not introduced with EXISTS'
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:ecvwdn1XFHA.1384@.TK2MSFTNGP09.phx.gbl...
> That would be one solution for that:
> Select TOP 2 * from TABLENAME
> Where Rowno <=
> (
> Select TOP 1 *
> from TABLENAME
> where detail ='prog crash'
> order by rowno
> )
> Order by row no desc
> I added the order by rowno if the detailcolumn is not precise enough,
> perhaps mor ethan one coumn would fit that condition, saythose with 4 and
> 105, should then the rows 3 AND 104 be returned, or is the detail column
> that precise only to return one row at a time ?
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Timmeah" <timoth@.optushome.com.au> schrieb im Newsbeitrag
> news:42916a43$0$10304$afc38c87@.news.optusnet.com.au...
>|||Ok, I setup a sample with the Northwind database which can be ported easily
for your case, try it and raise a hand if you stuck into it.
Select * from Orders O
Where CustomerID = 'VINET'
UNION
Select * from Orders
Where OrderID in
(
Select OrderID-1 from Orders O
Where CustomerID = 'VINET'
)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Timmeah" <timoth@.optushome.com.au> schrieb im Newsbeitrag
news:42917894$0$9263$afc38c87@.news.optusnet.com.au...
> yes would return 3 and 104 as well.
> that query gives an error
> 'Only one expression can be specified in the select list when the subquery
> is not introduced with EXISTS'
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in
> message news:ecvwdn1XFHA.1384@.TK2MSFTNGP09.phx.gbl...
>|||You missed the most basic idea of the Relational Model. Tables have no
ordering. Rows are not "lines" or "records". Those exists in file
systems. What does this "rowno" mean in your data model, and where
does it occur in the reality you are modeling?
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.|||>> I am pretty new to this so excuse any misunderstandings
Quite often people confuse the two dimensional representation of a table on
some visual medium ( a sheet of paper or a computer screen ) with the rows
sequentially arranged as if they can be navigated through like with a
recordset.
However, one of the basic tenets of relational databases is that, there is
no essential order associated with the rows in a table -- i.e. a row is
identified by <table_name, key_value> each and every value is identified by
the triplet <table_name, column_name, key_value). If the values in your
database cannot be identified this way, as a general rule, your design is
flawed. Therefore asking something about "previous line" does not really
make sense.
As a more specific suggestion, please read www.aspfaq.com/5006. Provide
DDLs, sample data & expected results for others to reproduce your problem
scenario.
Anith

Saturday, February 25, 2012

Preview error

This is my first report. I used VS.NET 2003 wizard to create the report,
which consisted of a very simple select query report.
When I switch to preview tab in IDE, I am getting the following error.
Processing Errors:
An error has occurred during report processing.
Cannot create a connecttion to data source 'xxx'.
Login failed for user 'yy'
Any ideas of why this is happening? I looked at rdl file in notepad. The
credentials supplied during report creation is not stored in that file.
Please help ASAP.
Thanks,
Live_Love_LaughIf you are using a shared data source, in solution explorer, double click on
the datasource file. Select the credentials tab. The problem is likely here.
If you are using SQL authentication, either enter a password or select the
option to prompt for a password. Let me know if this helps.
"Live_Love_Laugh" wrote:
> This is my first report. I used VS.NET 2003 wizard to create the report,
> which consisted of a very simple select query report.
> When I switch to preview tab in IDE, I am getting the following error.
> Processing Errors:
> An error has occurred during report processing.
> Cannot create a connecttion to data source 'xxx'.
> Login failed for user 'yy'
> Any ideas of why this is happening? I looked at rdl file in notepad. The
> credentials supplied during report creation is not stored in that file.
> Please help ASAP.
> Thanks,
> Live_Love_Laugh
>
>|||I am not using a shared data source. On the data tab, I can see the tables
and my query. But when I switch to preview tab to fetch the data, it is
giving the error. Also on the data tab, I can run the query and see the
results.
Thanks,
Live_Love_Laugh
"vmp_pdx" <vmppdx@.discussions.microsoft.com> wrote in message
news:60D5F30E-F474-4AA3-B6B9-5805A046B898@.microsoft.com...
> If you are using a shared data source, in solution explorer, double click
on
> the datasource file. Select the credentials tab. The problem is likely
here.
> If you are using SQL authentication, either enter a password or select the
> option to prompt for a password. Let me know if this helps.
> "Live_Love_Laugh" wrote:
> > This is my first report. I used VS.NET 2003 wizard to create the report,
> > which consisted of a very simple select query report.
> > When I switch to preview tab in IDE, I am getting the following error.
> >
> > Processing Errors:
> >
> > An error has occurred during report processing.
> > Cannot create a connecttion to data source 'xxx'.
> > Login failed for user 'yy'
> >
> > Any ideas of why this is happening? I looked at rdl file in notepad. The
> > credentials supplied during report creation is not stored in that file.
> >
> > Please help ASAP.
> >
> > Thanks,
> > Live_Love_Laugh
> >
> >
> >|||Can anybody help with this?
Thanks,
Live_Love_Laugh
"Live_Love_Laugh" <OnlineSubscribe@.yahoo.com> wrote in message
news:%23NTAPMvpEHA.2588@.TK2MSFTNGP12.phx.gbl...
> I am not using a shared data source. On the data tab, I can see the tables
> and my query. But when I switch to preview tab to fetch the data, it is
> giving the error. Also on the data tab, I can run the query and see the
> results.
> Thanks,
> Live_Love_Laugh
> "vmp_pdx" <vmppdx@.discussions.microsoft.com> wrote in message
> news:60D5F30E-F474-4AA3-B6B9-5805A046B898@.microsoft.com...
> > If you are using a shared data source, in solution explorer, double
click
> on
> > the datasource file. Select the credentials tab. The problem is likely
> here.
> > If you are using SQL authentication, either enter a password or select
the
> > option to prompt for a password. Let me know if this helps.
> >
> > "Live_Love_Laugh" wrote:
> >
> > > This is my first report. I used VS.NET 2003 wizard to create the
report,
> > > which consisted of a very simple select query report.
> > > When I switch to preview tab in IDE, I am getting the following error.
> > >
> > > Processing Errors:
> > >
> > > An error has occurred during report processing.
> > > Cannot create a connecttion to data source 'xxx'.
> > > Login failed for user 'yy'
> > >
> > > Any ideas of why this is happening? I looked at rdl file in notepad.
The
> > > credentials supplied during report creation is not stored in that
file.
> > >
> > > Please help ASAP.
> > >
> > > Thanks,
> > > Live_Love_Laugh
> > >
> > >
> > >
>|||Could you email to me your RDL?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Live_Love_Laugh" <OnlineSubscribe@.yahoo.com> wrote in message
news:OZEmZy$pEHA.2900@.TK2MSFTNGP12.phx.gbl...
> Can anybody help with this?
> Thanks,
> Live_Love_Laugh
> "Live_Love_Laugh" <OnlineSubscribe@.yahoo.com> wrote in message
> news:%23NTAPMvpEHA.2588@.TK2MSFTNGP12.phx.gbl...
>> I am not using a shared data source. On the data tab, I can see the
>> tables
>> and my query. But when I switch to preview tab to fetch the data, it is
>> giving the error. Also on the data tab, I can run the query and see the
>> results.
>> Thanks,
>> Live_Love_Laugh
>> "vmp_pdx" <vmppdx@.discussions.microsoft.com> wrote in message
>> news:60D5F30E-F474-4AA3-B6B9-5805A046B898@.microsoft.com...
>> > If you are using a shared data source, in solution explorer, double
> click
>> on
>> > the datasource file. Select the credentials tab. The problem is likely
>> here.
>> > If you are using SQL authentication, either enter a password or select
> the
>> > option to prompt for a password. Let me know if this helps.
>> >
>> > "Live_Love_Laugh" wrote:
>> >
>> > > This is my first report. I used VS.NET 2003 wizard to create the
> report,
>> > > which consisted of a very simple select query report.
>> > > When I switch to preview tab in IDE, I am getting the following
>> > > error.
>> > >
>> > > Processing Errors:
>> > >
>> > > An error has occurred during report processing.
>> > > Cannot create a connecttion to data source 'xxx'.
>> > > Login failed for user 'yy'
>> > >
>> > > Any ideas of why this is happening? I looked at rdl file in notepad.
> The
>> > > credentials supplied during report creation is not stored in that
> file.
>> > >
>> > > Please help ASAP.
>> > >
>> > > Thanks,
>> > > Live_Love_Laugh
>> > >
>> > >
>> > >
>>
>

Monday, February 20, 2012

Preventing overlapping data entry

Hello Everyone,

I have a web form that allows the user to select a time to reserve. I am trying to make it so that when a user selects a date to schedule something (which i have working) a drop down list will fill with times that have not been reserved.

The data is stored in two tables: tblCalendar and tblTime. tblTime contains pkTimeID and times (which are all possible times to select from in half hour intervals). tblCalendar contains a few fields but timeID and date (which is in the format M/d/yyyy) are what I need to test against. timeID is the foreign key of pkTimeID.

Basically when the user selects the date, a function gets called that will run a SELECT statement to get the times available. All of this works, I am able to fill the ddl with all times available no matter what the date is or what has already been reserved. I want to check if a time has been already selected based on the date selected by the user and only allow times not selected to be listed.

After acheiving this I would like to prevent the immediate time before and immediate time after from being displayed because each reserved time will last for one hour but the data is stored in half hour increments.

Any help/suggestions/links will be greatly appreciated. If I need to provide anything else please let me know.

Thanks in advance,

Brian

This query should give you the timeIDs that have not been scheduled:

SELECT t.pkTimeIDFROM tblTime tWHERE t.pkTimeIDNOT IN (SELECT c.timeIDFROM tblCalendar cWHERE c.date ='4/20/2007' )
Replace the date with the date the user has selected.|||

This query leaves out the prior and next time slots to avoid overlapping a one hour appointment.

SELECT t.pkTimeIDFROM tblTime tWHERE t.pkTimeIDNOT IN (SELECT unavailableTimes.timeIDFROM (SELECT c.timeID, c.dateFROM tblCalendar cLEFTJOIN tblTime tON t.pkTimeID = c.timeIDUNION SELECT t1.pkTimeID, c.dateFROM tblCalendar cLEFTJOIN tblTime tON t.pkTimeID = c.timeIDLEFTJOIN tblTime t1ON t1.time =SUBSTRING(CONVERT(VARCHAR(20),DATEADD(n, -30, c.date +' ' + t.time)), 14, 7)UNION SELECT t2.pkTimeID, c.dateFROM tblCalendar cLEFTJOIN tblTime tON t.pkTimeID = c.timeIDLEFTJOIN tblTime t2ON t2.time =SUBSTRING(CONVERT(VARCHAR(20),DATEADD(n, 30, c.date +' ' + t.time)), 14, 7) ) unavailableTimesWHERE unavailableTimes.date ='4/20/2007' )
This query is not optimal but you get the idea. Again, replace the date with the date the user has selected. You may also need to tweak the SUBSTRING params based on the format of your DATETIMEs.|||

Thank you so much for your help. I think I was a little to vague on my description but this solution helped me get a solution that worked for me. I needed to check for the previous and next pkTimeID value to eliminate not the actual datetime values. Just to keep this short my statement is as follows:

SELECT t.pkTimeID, t.timeFROM tblTime tWHERE t.pkTimeIDNOT IN (SELECT c.timeID - 1FROM tblCalendar cUNIONSELECT c1.timeIDFROM tblCalendar c1UNIONSELECT c2.timeID + 1FROM tblCalendar c2WHERE (c2.[date] ='4/20/2007'))

Thank you again for your help, and if you have any suggestions on how I might improve what I did come up with I would appreciate it. This is my first "real" project in the work place and I would like to learn the best way to approach a problem where ever I can, so that I will not have to learn these things later.

Brian