Showing posts with label successfully. Show all posts
Showing posts with label successfully. Show all posts

Friday, March 30, 2012

How to Create reference for Composite key

Hi All,

Can anyone tell me how to create a reference for composite key.

For ex, I have created tblEmp table successfully.

create tblEmp

(

empId varchar(100),

RegId varchar(100),

empname varchar(100),

constraint pk_add

primary key(empId, RegId)

)

And now, I am going to create another table which references the composite key.

create table tblAccount

(

acctId varchar(100) primary key,

empId varchar(100) references tblEmp(empId),

RegId varchar(100) references tblEmp(RegId)

)

But it gives error like

Server: Msg 1776, Level 16, State 1, Line 1
There are no primary or candidate keys in the referenced table 'tblEmp' that match the referencing column list in the foreign key 'FK__tbl'.
Server: Msg 1750, Level 16, State 1, Line 1
Could not create constraint. See previous errors.

Could anyone please let me know how to create reference for composite key.

Thanks in advance,

Arun.

The below code will do:

create table tblEmp( empIdvarchar(100), RegIdvarchar(100), empnamevarchar(100),constraint pk_addprimary key(empId, RegId) )create table tblAccount( acctIdvarchar(100)primary key, empIdvarchar(100) , RegIdvarchar(100),constraint fk_tblAccountforeign key ( empId, RegId)references tblEmp( empId, RegId) )

In case you've already created both tables, you can use below query to set the foreign key in the account table.

alter table tblAccountadd constraint fk_tblAccountforeign key ( empId, RegId)references tblEmp( empId, RegId)

Hope this will help.

|||

Hi,

We can also do it by

create tblEmp

(

empId varchar(100),

RegId varchar(100),

empname varchar(100),

primary key(empId, RegId)

)

And now, I am going to create another table which references the composite key.

create table tblAccount

(

acctId varchar(100) primary key,

empId varchar(100) ,

RegId varchar(100) ,

foreign key(empId,RegId) references tblEmp(empId,RegId)

)

It works perfect

|||

arunkumar.niit:

primary key(empId, RegId)

arunkumar.niit:

foreign key(empId,RegId) references tblEmp(empId,RegId)

Hey, your queries are exactly the same as what I've posted except one thing that I've given my own names to the constraints and you've left it over the SQL Server.

|||

Hi,

Thanks for your reply.

Thanks & Regards,

Arun.

Monday, March 12, 2012

How to create a group on selected report parameters?

Hello,
Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
states in a report that returns orders.
I successfully can return order numbers along with the associated state
where the order was placed.
However, if I select the states of NH, VT, and MA and there are no orders
from VT, I still need a group header for VT to show that there was no data
for VT. So my thought was to create a report grouping based on the states
selected in the multivalue State parameter. I can't find a way to do this.
Also, I know I could use a subreport to resolve this but it is not an option
here. I need this report to be exported to MS Excel and subreports do not
export to Excel.
Thank you,
JustinOn Oct 3, 3:48 pm, justinsaraceno
<justinsarac...@.discussions.microsoft.com> wrote:
> Hello,
> Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
> states in a report that returns orders.
> I successfully can return order numbers along with the associated state
> where the order was placed.
> However, if I select the states of NH, VT, and MA and there are no orders
> from VT, I still need a group header for VT to show that there was no data
> for VT. So my thought was to create a report grouping based on the states
> selected in the multivalue State parameter. I can't find a way to do this.
> Also, I know I could use a subreport to resolve this but it is not an option
> here. I need this report to be exported to MS Excel and subreports do not
> export to Excel.
> Thank you,
> Justin
>From your description, you will most likely want to insert dummy rows
in the returned dataset from the stored procedure/query that is
sourcing the report based on the parsing out of the multi-select
parameter. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||Thank you Enrique. It's not the answer I wanted to hear but I suppose it's a
possible solution. I wish there was a better way than having to manipulate
my dataset with dummy data. Thank you again.
"EMartinez" wrote:
> On Oct 3, 3:48 pm, justinsaraceno
> <justinsarac...@.discussions.microsoft.com> wrote:
> > Hello,
> > Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
> > states in a report that returns orders.
> >
> > I successfully can return order numbers along with the associated state
> > where the order was placed.
> >
> > However, if I select the states of NH, VT, and MA and there are no orders
> > from VT, I still need a group header for VT to show that there was no data
> > for VT. So my thought was to create a report grouping based on the states
> > selected in the multivalue State parameter. I can't find a way to do this.
> >
> > Also, I know I could use a subreport to resolve this but it is not an option
> > here. I need this report to be exported to MS Excel and subreports do not
> > export to Excel.
> >
> > Thank you,
> > Justin
>
> >From your description, you will most likely want to insert dummy rows
> in the returned dataset from the stored procedure/query that is
> sourcing the report based on the parsing out of the multi-select
> parameter. Hope this helps.
> Regards,
> Enrique Martinez
> Sr. Software Consultant
>|||Hi,
I have the same problem. Did you find any solution to that?
--
Thanks,
Tabbey
"justinsaraceno" wrote:
> Thank you Enrique. It's not the answer I wanted to hear but I suppose it's a
> possible solution. I wish there was a better way than having to manipulate
> my dataset with dummy data. Thank you again.
> "EMartinez" wrote:
> > On Oct 3, 3:48 pm, justinsaraceno
> > <justinsarac...@.discussions.microsoft.com> wrote:
> > > Hello,
> > > Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
> > > states in a report that returns orders.
> > >
> > > I successfully can return order numbers along with the associated state
> > > where the order was placed.
> > >
> > > However, if I select the states of NH, VT, and MA and there are no orders
> > > from VT, I still need a group header for VT to show that there was no data
> > > for VT. So my thought was to create a report grouping based on the states
> > > selected in the multivalue State parameter. I can't find a way to do this.
> > >
> > > Also, I know I could use a subreport to resolve this but it is not an option
> > > here. I need this report to be exported to MS Excel and subreports do not
> > > export to Excel.
> > >
> > > Thank you,
> > > Justin
> >
> >
> > >From your description, you will most likely want to insert dummy rows
> > in the returned dataset from the stored procedure/query that is
> > sourcing the report based on the parsing out of the multi-select
> > parameter. Hope this helps.
> >
> > Regards,
> >
> > Enrique Martinez
> > Sr. Software Consultant
> >
> >|||I didn't find anything better than creating some dummy data via something
like a temp table. If SSRS supported export to excel for reports with
subreports, there wouldn't be such a hack to get around this.
"tabbey" wrote:
> Hi,
> I have the same problem. Did you find any solution to that?
> --
> Thanks,
> Tabbey
>
> "justinsaraceno" wrote:
> > Thank you Enrique. It's not the answer I wanted to hear but I suppose it's a
> > possible solution. I wish there was a better way than having to manipulate
> > my dataset with dummy data. Thank you again.
> >
> > "EMartinez" wrote:
> >
> > > On Oct 3, 3:48 pm, justinsaraceno
> > > <justinsarac...@.discussions.microsoft.com> wrote:
> > > > Hello,
> > > > Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
> > > > states in a report that returns orders.
> > > >
> > > > I successfully can return order numbers along with the associated state
> > > > where the order was placed.
> > > >
> > > > However, if I select the states of NH, VT, and MA and there are no orders
> > > > from VT, I still need a group header for VT to show that there was no data
> > > > for VT. So my thought was to create a report grouping based on the states
> > > > selected in the multivalue State parameter. I can't find a way to do this.
> > > >
> > > > Also, I know I could use a subreport to resolve this but it is not an option
> > > > here. I need this report to be exported to MS Excel and subreports do not
> > > > export to Excel.
> > > >
> > > > Thank you,
> > > > Justin
> > >
> > >
> > > >From your description, you will most likely want to insert dummy rows
> > > in the returned dataset from the stored procedure/query that is
> > > sourcing the report based on the parsing out of the multi-select
> > > parameter. Hope this helps.
> > >
> > > Regards,
> > >
> > > Enrique Martinez
> > > Sr. Software Consultant
> > >
> > >|||On Oct 4, 8:08 am, justinsaraceno
<justinsarac...@.discussions.microsoft.com> wrote:
> Thank you Enrique. It's not the answer I wanted to hear but I suppose it's a
> possible solution. I wish there was a better way than having to manipulate
> my dataset with dummy data. Thank you again.
> "EMartinez" wrote:
> > On Oct 3, 3:48 pm, justinsaraceno
> > <justinsarac...@.discussions.microsoft.com> wrote:
> > > Hello,
> > > Using SSRS 2005 SP2, I have a report that has a multivalue parameter of US
> > > states in a report that returns orders.
> > > I successfully can return order numbers along with the associated state
> > > where the order was placed.
> > > However, if I select the states of NH, VT, and MA and there are no orders
> > > from VT, I still need a group header for VT to show that there was no data
> > > for VT. So my thought was to create a report grouping based on the states
> > > selected in the multivalue State parameter. I can't find a way to do this.
> > > Also, I know I could use a subreport to resolve this but it is not an option
> > > here. I need this report to be exported to MS Excel and subreports do not
> > > export to Excel.
> > > Thank you,
> > > Justin
> > >From your description, you will most likely want to insert dummy rows
> > in the returned dataset from the stored procedure/query that is
> > sourcing the report based on the parsing out of the multi-select
> > parameter. Hope this helps.
> > Regards,
> > Enrique Martinez
> > Sr. Software Consultant
You're welcome. Sorry that I could not be of greater assistance.
Regards,
Enrique Martinez
Sr. Software Consultant

Sunday, February 19, 2012

How to copy MSSQL DB

Hi

I'm a newbie with MSSQL. I hv MSSQL 7.0 running successfully on my notebook as a test environment & the folder is \MSSQL7\DATA. We have a production server running live. There are 2 files called recruitment.mdf & recruitment_log.ldf which resides on the server but is not in my notebook. When i copy it to my notebook, the Enterprise Mgr does not recognise it. It does not show in the database list. Why? What shld I do?? I wud appreciate step-by-step instructions. ThanksWhat do u mean "Enterprise Mgr does not recognise it"? U just copied the mdf and ldf files, or u have attached the database but still not show up at Enterprise Manager, or u even failed to attach it?|||please see the sp_attach_db and sp_detach_db system stored procedures in sql server book online. You can also do a backup and restore using the replace argument of the RESTORE DATABASE command over a blank database. The former is what I usually do. I do not think SQL 7 had the copy database wizard (that was so long ago) but if it does, stay away from it. It's a pain.