|
USE master
Go
EXEC sp_addlogin NewUser, password, dbName
Go
Where NewUser is the User Name, password is the user password, and dbName is the name of the database that you want to add the user to.
Or, if you are using Windows authentication, add users to roles in SSMS.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
The above method is to add user login to the database.
But the OP is asking to set user id and password to the .MDF file as we can do it for MS Access files.
AFAIK, We cannot set user id and password to the database files(.MDF and .LDF).
|
|
|
|
|
dotnet buddy wrote: AFAIK, We cannot set user id and password to the database files(.MDF and .LDF).
Correct.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
I am putting together a web site that includes a SQL Server Express 2008 file. I use VWD 2008 Express and SQL Server Management Studio 2008. It is not designated as an Express version. I have a number of tables and have developed a view between two of them. I have a web page where I want to add, edit and delete records from the second table. The first table has two columns- a UID column and a use name column. The second table has a UID column that relates the two tables. The other columns are a Use name column, a DID column a NID column and a NID name column.
Why, when I click on the GridView tasks button and go to configure datasource, accept the connection string, go to the next form and check "specify columns from a table or view" and select K-Use K-UseUseSet, the name of the view I created, and check all the columns- UID, Use, DID, NID and Name, why when I check "advanced" do I find the items "Generate INSERT,UPDATE AND DELETE statements" and "Use optimistic concurrency" shaded out so I can't select them and therefore can't do the Edit and Delete commands in the Gridview?
Yes, I know the GRidView doesn't do adds. I have to use a DetailsView.
What am I missing?
Try not to give me any pages from MSFT. They are usually very optuse and talk in terms I don't understand.
My background is Access and I have had very good results with it. The file I am presently working on came from Access.
Specifically, I'd like to know what to click on to make this sort of scenario workable. Essentially, the question is how does one add, change and delete records when the table to be changed is a relation of two or more tables in a view?
I appreciate your help.
|
|
|
|
|
You can't update a multi-table view, thats what your problem is.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I have a table like below.
CREATE TABLE [dbo].[BatchProcessRule](
[BatchProcessRuleId] [int] IDENTITY(1,1) NOT NULL,
[EffectiveDate] [datetime] NOT NULL,
[EndDate] [datetime] NULL,
[LastModifiedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[LastModifiedOn] [datetime] NOT NULL)
How can I create a constraint so that only one row may exists with a null EndDate?
I tried using the constraint text (select count (*) from BatchProcessRuleDetail where EndDate is null ) > 1
but I got an error saying subqueries are not allowed.
Any thought?
I didn't get any requirements for the signature
|
|
|
|
|
How about this ?
CREATE TABLE [dbo].[BatchProcessRule](
[BatchProcessRuleId] [int] IDENTITY(1,1) NOT NULL,
[EffectiveDate] [datetime] NOT NULL,
[EndDate] [datetime] CONSTRAINT BatchProcessRule_UNIQUE UNIQUE,
[LastModifiedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[LastModifiedOn] [datetime] NOT NULL)
Making a column unique means it would take its value NULL but only once.
|
|
|
|
|
That will only work if the EndDates are unique.
|
|
|
|
|
Isnt that what he wanted ?
|
|
|
|
|
No, he wanted only 1 null - that says nothing about the uniqueness of the non-nulls.
|
|
|
|
|
I don't think you can do this via a constraint.
You might be able to do this with a trigger that runs on insert/update to check the date and raise an error if it violates your rule.
Another possibility might be to restrict update and insert permissions to the table so that the only way to update/insert is via a stored procedure which does the check for null dates and raises an error accordingly.
|
|
|
|
|
I am only using a stored proc to do the update, so I'm just going to leave it that way. I just like to set up all my relationships / constraints before I start developing. I can recall at least 3 or 4 times where database rules have prevented small bugs from causing major headaches.
I didn't get any requirements for the signature
|
|
|
|
|
Hi,
How can I find all leaves (nodes that don't have any child), in a hierarchy structure in my table in sql?
Best wishes
|
|
|
|
|
Peronally, when I represent Heirachies in a relational table I always add a boolean "IsLeaf" field so I can query just this situaltion easily (SELECT * FROM MyHeirachy WHERE IsLeaf=1 )
However, it should be easy enough without it, just look for any rows where there is no row referencing this row as its parent.
SELECT *
FROM MyHeirachy H
WHERE NOT EXISTS (SELECT * FROM MyHeirachy WHERE ParentID=H.ID)
|
|
|
|
|
The following code uses the Employees table from Northwind.
WITH EmployeeStructure
AS
(
SELECT employeeid, reportsto, 0 as level
FROM Employees
WHERE reportsto is null
UNION ALL
SELECT e.employeeid, e.reportsto, level + 1
FROM Employees e
INNER JOIN EmployeeStructure es
ON es.employeeid = e.reportsto
)
SELECT *
FROM EmployeeStructure
WHERE EmployeeID NOT IN (SELECT reportsto FROM EmployeeStructure GROUP BY reportsto HAVING ReportsTo IS NOT NULL)
ORDER BY level ASC
|
|
|
|
|
Hi, I have a XML column (name = 'xml') in a table 'contact' in my DB which has rows as the following
<Contact xmlns="http://www.focus-solutions.co.uk/focus360/1.0" id="00496bb7-0046-4459-8cf8-002cc5921f4c" documentId="494f4671-efe8-4577-aecc-4424b699a89c">
<Type code="FirstMeeting">First meeting</Type>
<Location code="ClientHome">Client Home</Location>
<PresentationInd>true</PresentationInd>
<OtherAddress>
<HouseNameNumber>1</HouseNameNumber>
<AddressLine1>Royal Terrace Gardens</AddressLine1>
<City>Edinburgh</City>
<Postcode>EH7 5DX</Postcode>
</OtherAddress>
<Date>2009-09-08</Date>
<Time isoTime="15:00:00">
<Hours>03</Hours>
<Minutes>00</Minutes>
<Period>PM</Period>
</Time>
<Duration>
<Hours>01</Hours>
<Minutes>00</Minutes>
</Duration>
<Notes />
<LetterSentInd>true</LetterSentInd>
<Documents>
<Document id="a7b36eec-ed51-4f22-8465-267a893fd8a0" externalId="494f4671-efe8-4577-aecc-4424b699a89c" userAttached="false">
<Type code="ConfirmationLetter">Confirmation Letter</Type>
<Reference>Joe Marton First meeting</Reference>
<CreatedDate>2009-09-18</CreatedDate>
</Document>
</Documents>
<CustomQuestions>
<Question type="HasMeetingTakenPlace">
<Answer>true</Answer>
</Question>
<Question type="ClientContacted">
<Answer>Joe Marton</Answer>
</Question>
</CustomQuestions>
<Valid>true</Valid>
</Contact>
So this is just one row in the table.I am complete beginner when it comes to querying XML datatypes in a table.
I need to be able to list all records in the table CONTACT for which the the value <PresentationInd>true</PresentationInd> is true.
Help appriciated
|
|
|
|
|
SSRS - Web Service vs URL access. Pro's and Con's?
Thanks
dev
|
|
|
|
|
|
um... I've written apps which accesses SSRS reports via URL access, and I've written apps which accesses SSRS reports via Web Services.
This article is for someone who hasn't done it...
dev
|
|
|
|
|
Turns out I was specifying the length of the XML string from the application. Goes to show how dumb one can be sometimes!
This error has been driving me mad. Testing the whole run from within SSMS using the same values that are provided by the application yields a perfectly working result; The application itself returns "XML parsing: line 1, character 4, unexpected end of input"
The actual XML being sent is:
<Data>
<AssignedDiet>
<PatientID>127686419</PatientID>
<AdmittanceID>3</AdmittanceID>
<DietID>1</DietID>
<Notes></Notes>
</AssignedDiet>
</Data>
The stored procedure called is:
<pre>
------------------------------------------------------------------------------------------------------------------------
-- Author: Mustafa Ismail Mustafa
-- Procedure Name: [EMR].[NV_VW_Orders_Diet_Insert]
-- Date Generated: Sunday, August 09, 2009
-- Company: Netvareas Solutions
-- Project Name: RCH Automation
------------------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE [EMR].[NV_VW_Orders_Diet_Insert]
@PatientID char(10),
@AdmittanceID int,
@IssuingEmployeeID int,
@DateTimeGiven datetime,
@OrderDetails nvarchar(max),
@IsDoctor bit,
@IsCanceled bit,
@IsCompleted bit,
@ClosingEmployeeID int,
@ClosingDateTime datetime,
@IsRepeated bit,
@IsDefaultTime bit,
@DefaultTimeID int,
@PeriodID int,
@PeriodValue int,
@Notes nvarchar(max),
@DietID int,
@OrderType nvarchar(50),
@Tags XML,
@SubOrderID int OUTPUT,
@OrderID int OUTPUT
AS
SET NOCOUNT ON
BEGIN TRANSACTION
/*
1. Retrieve the SubOrderID (Max current DietOrderID + 1)
2. Insert the PatientOrder and retrieve the OrderID
3. Insert the DietOrder
4. Extract from the XML all the rows to be inserted into mmPatientDiets
5. Insert rows into the persistant table mmPatientDiets
*/
DECLARE @ERR int = 0;
--1.
SET @SubOrderID = ISNULL((SELECT MAX(DietOrderID) FROM EMR.PatientAssignedDiets WHERE PatientID = @PatientID AND AdmittanceID = @AdmittanceID),0) + 1;
--2.
EXEC [EMR].[NV_PatientOrders_Insert]
@PatientID, @AdmittanceID, @DateTimeGiven, @IssuingEmployeeID, @OrderDetails, @IsDoctor, @IsCanceled,
@IsCompleted, @IsRepeated, @IsDefaultTime, @DefaultTimeID, @PeriodID, @PeriodValue, @OrderType,
@SubOrderID, @OrderID OUTPUT
SET @ERR = (SELECT @@ERROR)
if @ERR &lt;&gt; 0
GOTO ErrorHandler
--3.
EXEC [EMR].[NV_PatientAssignedDiets_Insert]
@PatientID, @AdmittanceID, @OrderID, @SubOrderID
SET @ERR = (SELECT @@ERROR)
if @ERR &lt;&gt; 0
GOTO ErrorHandler
--4.
EXEC sp_xml_preparedocument @Handle OUTPUT, @Tags
SET @ERR = (SELECT @@ERROR)
if @ERR &lt;&gt; 0
GOTO ErrorHandler
--5.
INSERT INTO EMR.mmPatientDiets
SELECT PatientID, AdmittanceID,@OrderID,@SubOrderID, DietID, Notes, GETDATE(), null
FROM OPENXML (@Handle, '/Data/AssignedDiet', 2) WITH
(PatientID char(10), AdmittanceID int, DietID int, Notes nvarchar(max) );
SET @ERR = (SELECT @@ERROR)
if @ERR &lt;&gt; 0
GOTO ErrorHandler
ErrorHandler:
IF @ERR &lt;&gt; 0
BEGIN
Rollback
RETURN @Err
END
COMMIT
</pre>
I don't know what else to post, but I'd be more than happy to oblige. What makes it absolutely annoying is that it works fine from SSMS!
TIA
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
modified on Saturday, September 26, 2009 4:45 PM
|
|
|
|
|
hi
how i can run this:
select * from men where Tdate between 01/01/01 and 02/02/02
but, Tdate is nvarchar type
i work with sqlCE
thank's
|
|
|
|
|
Hi,
I would convert the string to a real datetime using convert(datetime, Tdate) , then use that in a WHERE clause.
it could be something like ... where convert(datetime, Tdate, 1)>='01/01/01' and convert(datetime, Tdate, 1)<='02/02/02'
The '1' code specifies the format, see here[^].
I would also suggest to STORE dates as such, not as strings.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc has given you the solution but he was not forceful enough on storing the data as a datetime data type. If you do not change your data format to datetime then you will continiously run into this problem and all the associated datetime issues we see here regularly.
STORE YOUR DATA IN THE RIGHT FORMAT.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: he was not forceful enough
Sorry, I must be having an off-day then.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
As we are no longer encouraged to beat them with the sarcasm stick , I see no reason not to scream it in their face.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|