I cannot store the date data type variables using stored procedure. My code is:
ALTER PROCEDURE [dbo].[Access1Register]
-- Add the parameters for the stored procedure here
@MobileNumber int,
@CitizenName varchar(50),
@Dob char(8),
@VerificationCode int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select CAST(@dob As DATE)
Insert Into Access1 (MobileNo,CitizenName,Dob,VerificationCode)
values(@MobileNumber,@CitizenName,@Dob,@VerificationCode)
go
If I exec this procedure it is executing, but there is an error occured in the date type variable. It's raising the error as invalid item '-'.
I have a Table called Address. I have a Trigger for insert on that table that does some spacial calculations on the address that determines what neighborhood boundaries it is in.
address = new Address
{
Street = this.Street,
City = this.City,
State = this.State,
ZipCode = this.ZipCode,
latitude = this.Latitude,
longitude = this.Longitude,
YearBuilt = this.YearBuilt,
LotSize = this.LotSize,
FinishedSize = this.FinishedSize,
Bedrooms = this.Bedrooms,
Bathrooms = this.Bathrooms,
UseCode = this.UseCode,
HOA = this.HOA,
UpdateDate = DateTime.Now
};
db.AddToAddresses(address);
db.SaveChanges();
In the database i can clearly see that the Trigger ran and updated the neighborhoodID in the address table for the row. I tried to just reload that record to get the assigned id like this:
address = (from a in db.Addresses where a.AddressID == address.AddressID select a).First();
In the debugger i can clearly see that the address.AddressID is correct, entity doesn't update in memory.
Is there any work around for this?
Hello
How to check a value IS NULL [or] = @param (where @param is null)
Ex:
Select column1 from Table1
where column2 IS NULL => works fine
If I want to replace comparing value (IS NULL) with @param. How can this be done
Select column1 from Table1
where column2 = @param => this works fine until @param got some value in it and if is null never finds a record.
How can this achieve?
Hey,everyone
I have a string 'some.file.name',I want to grab 'some.file'.
To do that,I need to find the last occurrence of '.' in a string.
My solution is :
declare @someStr varchar(20)
declare @reversedStr varchar(20)
declare @index int
set @someStr = '001.002.003'
set @reversedStr = reverse(@someStr)
set @index = len(@someStr) - charindex('.',@reversedStr)
select left(@someStr,@index)
Well,isn't it too complicated?I was just intented to using 'some.file' in a where-clause.
Anyone has a good idea?
declare @mydata nvarchar(4000)
set @mydata = '36|0, 77|5, 132|61'
I have this data that I need to get into a table. So for Row1 columnA would be 36 and columnB would be 0. For Row2 columnA would be 77 and columnB would be 5 etc.
What is the best way to do this?
Thanks
I'd like to get the total count of results and top n rows of some query - is it possible
in one statement?
I'd expect the results as:
count(..) column1 column2
125 some_value some_value
125 some_value some_value
Thank you in advance!
Hi, i've got stuck with substring.
On input i've got a string that looks like Sometext (123456). Those digits at the end are random. I need to get only text from that string.
Hi. I'm developing a simple database architecture in VisualParadigm and lately ran over next code excerpt.
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'getType') AND type in (N'P', N'PC'))
DROP PROCEDURE getType;
Next goes my stored procedure:
CREATE PROCEDURE getType @typeId int
AS
SELECT * FROM type t WHERE t.type_id = @typeId;
Can anyone explain what does it mean?
P.S.: It would be great, if you may also check for any syntax errors as I'm totally new to MSSQL and stored procedures.
While studying for the 70-433 exam I noticed you can create a covering index in one of the following two ways.
CREATE INDEX idx1 ON MyTable (Col1, Col2, Col3)
-- OR --
CREATE INDEX idx1 ON MyTable (Col1) INCLUDE (Col2, Col3)
The INCLUDE clause is new to me. Why would you use it and what guidelines would you suggest in determining whether to create a covering index with or without the INCLUDE clause?
I am trying to convert rows into columns. here is my query
SELECT M.urn,
M.eventdate,
M.eventlocation,
M.eventroom,
M.eventbed,
N.time
FROM admpatevents M
INNER JOIN admpattransferindex N
ON M.urn = N.urn
AND M.eventseqno = N.eventseqno
AND M.eventdate = N.eventdate
WHERE M.urn = 'F1002754364'
AND M.eventcode = 'TFRADMIN'
Current result
URN Date Location Room Bed Time
F1002754364 20121101 EDEXPRESS 4-152 02 0724
F1002754364 20121101 CARDSURG 3-110 02 1455
F1002754364 20121102 CHEST UNIT 6-129-GL04 1757
required result
F1002754364 20121101 EDEXPRESS 4-152 02 0724 20121101 CARDSURG 3-110 02 1455 20121102 CHEST UNIT 6-129-GL 04 1757
Thanks for your help.
I have a large historical transaction table (15-20 million rows MANY columns) and a table with one row one column. The table with one row contains a date (last processing date) which will be used to pull the data in the trasaction table ('process_date').
Question: Should I inner join the 'process_date' table to the transaction table or the transaction table to the 'process_date' table?
I have a TimeSheet table as:
CREATE TABLE TimeSheet
(
timeSheetID
employeeID
setDate
timeIn
outToLunch
returnFromLunch
timeOut
);
Employee will set his/her time sheet daily, i want to ensure that he/she doesn't cheat. What should i do?
Should i create a column that gets date/time of the system when insertion/update happens to the table and then compare the created date/time with the time employee's specified - If so in this case i will have to create date/time column for timeIn, outToLunch, returnFromLunch and timeOut. I don't know, what do you suggest?
Note: i'm concerned about tracking these 4 columns timeIn, outToLunch, returnFromLunch and timeOut
In my development/test environment on my laptop, I can't back up the SQLserver database files because the file handles are kept permanently open by SQLserver (VSS doesn't work because the drive is truecrypted)
I was hoping there may be some setting in SQLserver that can make it unlock the data files after a certain period of inactivity and automatically open them again on demand, but I can't find anything.
I don't really want to be dumping the database out every night because it's only a development environment. apart from stopping sqlserver before I do the backup is there any other solution?
Basically, having this table:
12.10
2.35
21.45
35.26
I want to, in each record, calculate the sum of all previous records, like this:
12.10 | 12.10
2.35 | 14.45
21.45 | 35.90
35.26 | 71.16
I am attempting to replace all records for a give day in a certain table. The table has a composite primary key comprised of 7 fields. One such field is date.
I have deleted all records which have a date value of 2/8/2010. When I try to then insert records into the table for 2/8/2010, I get a primary key violation. The records I am attempting to insert are only for 2/8/2010.
Since date is a component of the PK, shouldn't there be no way to violate the constraint as long as the date I'm inserting is not already in the table?
Thanks in advance.
select @[email protected]('*')
for xml raw,type
Above statement will generate following alert:
Msg 6819, Level 16, State 3, Line 2
The FOR XML clause is not allowed in a ASSIGNMENT statement.
I'm looking for hosted solutions but there are so many companies that finding the right one using a Google search is a bit overwhelming. Ideally I would like a hosting company which has following options:
-Linux VPSs - Individual VPSs should be fairly cheap since I plan on putting one or two services per VPS i.e web server on one (httpd and ColdFusion), an SVN server on another, etc.
-Managed MS SQL databases - My company already has data in MS SQL databases and a lot of ColdFusion code written that has MS SQL specific commands in it.
-Individually purchased dedicated IP addresses
-Preferably located in the North America region
My plan would be to setup one Linux VPS as a gateway/firewall/VPN server and have all of my traffic routed through so that my other servers would not use of bandwidth by talking to each other. The trick is also finding a company that does Linux VPS AND MS SQL databases.
Does anybody know of any hosting companies offer what I'm looking for?
Let me know if I need to add more details.
Hi
I am wondering how can do a mass insert and bulk copy at the same time? I have 2 tables that should be affect by the bulk copy as they both depend on each other.
So I want it that if while inserting table 1 a record dies it gets rolled back and table 2 never gets updated. Also if table 1 inserts good and table 2 an update fails table 1 gets rolled back.
Can this be done with bulk copy?
I thought I had this figured out but it turns out I'm just deleting the first record. The following returns the duplicate rows. All have a count of 2. I just want to delete the first one for each duplicate record.
select scorestudentid, scoreadvisor, scorecorrect, count(*)
from scores
where scoretestid = 3284
group by scorestudentid, scoreadvisor, scorecorrect
having count(scorestudentid) > 1
Which returns:
scorestudentid scoreadvisor scorecorrect no column name
13033719 28059 3.0 2
13033777 28086 3.0 2
13033826 28147 3.0 2
13033960 28023 3.0 2
So I put this together thinking it would work:
set rowcount 1
delete
from scores
where scoretestid = 3284
and scorestudentid in (
select scorestudentid
from scores
where scoretestid = 3284
group by scorestudentid
having count(scorestudentid) > 1)
It really seems like it should be a simple concept but I'm not getting it.
Let's say we have a view V1 and V2 that is declared like:
create view V2 as
select V1.*, V2.C1, V2.C2, V2.C3
from V1
join V2 on V1.Key = V2.Key
where bla-bla
So V2 narrows down the result set of V1 and adds some joins. And there is a retrieval routine in C#
IEnumerable<V1> GetData(MyFilter filter, MySortOrder order) {}
I want to reuse with V2. Is it possible without performing joins in L2S rather than in database? Should i manually create a base class in the database context or something?
I would like to use newId to generate random numbers. Usually you would use it just once, but I might be generating up to 10 random numbers per newId.
Is it random enough?
Hi:
Subject:
SQLServer 2000 Enterprise Edition, windows XP
Log-in fail for odbc sqlserver user computer name/guest
I am connecting for several computer with the VB6 application with following connection string
"PROVIDER=MSDASQL;driver={SQL Server};server=Computer Name.;uid=;pwd=;database=Test Name;"
BUT, just Three Computer not Log-in. This three (connected with each other) are completely separate in other Room.
I checked all possible options. Besides, which option is missing???
Please Help me...
i've created a function for convert minutes (smallint) in time (varchar(5))
like 58 - 00:58
set QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[IntToMinutes]
(
@m smallint
)
RETURNS nvarchar(5)
AS
BEGIN
DECLARE @c nvarchar(5)
SET @c = CAST((@m / 60) as varchar(2)) + ':' + CAST((@m % 60) as varchar(2))
RETURN @c
END
The problem is when there are minutes < 10 in time
like 9
the result of this function is 0:9
i want that the format is 00:09
how can i do that?
Below is my query. Access does not like it, giving me the error Syntax error (missing operator) in query expression 'answer WHERE question = 1'.
Hopefully you can see what I am trying to do. Please pay particular attention to 3rd, 4th, and 5th lines under the SELECT statement.
INSERT INTO Table2 (respondent,1,2,3-1,3-2,3-3,4,5)
SELECT respondent,
answer WHERE question = 1,
answer WHERE question = 2,
answer WHERE answer = 'text 1' AND question = 3,
answer WHERE answer = 'text 2' AND question = 3,
answer WHERE answer = 'text 3' AND question = 3,
answer WHERE question = 4,
longanswer WHERE question 5 FROM Table1 GROUP BY respondent;