June 20, 2009 at 10:18 am
Create table Patient (PatientId int,
FullName varchar(30),
flag char(1)
constraint ss check (adp = 't' or adp = 'f')
)
i want to store only T or F in the flag field . for example if i enter 't' it should be stored as 'T' and vice versa.
any help would be very usefull.
June 20, 2009 at 10:25 am
1. you can put this conversion on the front end application that will convert the field to uppercase...
2. i dont know if this the best practice but you can write a insert/udpate trigger that causes the insert/update of this column in upper case.
June 20, 2009 at 11:28 am
pradeep's suggestion for a trigger to uppercase the input would work, and you could force only the upper case values to be inserted with a slightly different constraint:
Create table Patient (PatientId int,
FullName varchar(30),
flag char(1)
constraint ss check (ascii(adp) = 84 or ascii(adp) = 70) --'T' or 'F',116 or 102 for 't' or 'f'
)
Lowell
June 20, 2009 at 11:47 am
If you are using a stored procedure to input the data you could use:'INSERT INTO dbo.Patient(Patientid,fullname,flag)
VALUES(1002,'my full name is',UPPER('f'))
If using a stored procedure to extract the data and pass it to your interface application use:
SELECT patientid, fullname,UPPER(flag) FROM dbo.patient
Or use either Lowell's or ps's suggestions - either way hope this assists you
June 20, 2009 at 10:41 pm
smsam1 (6/20/2009)
i want to store only T or F in the flag field . for example if i enter 't' it should be stored as 'T' and vice versa.
Why? Is your server case sensitive? If not, it will not matter in any of your code except that forcing it to change will only take extra time and resources.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 21, 2009 at 6:56 am
since i want only to show 't' or 'f' in upper case letters, i will use
select upper(flag)
from patient
thank you for everyone who helped me!
June 21, 2009 at 7:05 am
smsam1 (6/21/2009)
since i want only to show 't' or 'f' in upper case letters, i will useselect upper(flag)
from patient
thank you for everyone who helped me!
You first post said u want to store caps letter in that field. It seems now u're okay with storing lower caps and then showing it as upper caps.
Anyways glad you got it working as per your requirement:-).
June 24, 2009 at 10:13 am
oh dear don think abt it
'cause user requirements change very rapidly
June 24, 2009 at 11:13 am
The database is not suppose to format data on the fly, that's not it's job. RDMS are very weak at computational stuff like formatting. This should be handled in the middle-tier/front-end.
June 27, 2009 at 7:35 pm
sqlguru (6/24/2009)
The database is not suppose to format data on the fly, that's not it's job. RDMS are very weak at computational stuff like formatting. This should be handled in the middle-tier/front-end.
Heh... I halfway agree... you can do some awesome highspeed formatting in SQL Server and, in the absence of a GUI or reporting program, such formatting is perfect for batch formatting of information destined to become a file. Other than that, I agree. Formatting should be done on the GUI side but not because of any short coming on the SQL Server side... it's because you want the local settings to be able to do the conversion on the GUI side. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
June 29, 2009 at 6:03 am
Or use COLLATION
CONSTRAINT ss CHECK (adp IN ('T', 'F') COLLATE SQL_Latin1_General_Cp437_BIN)
N 56°04'39.16"
E 12°55'05.25"
June 29, 2009 at 6:41 am
Peso (6/29/2009)
Or use COLLATIONCONSTRAINT ss CHECK (adp IN ('T', 'F') COLLATE SQL_Latin1_General_Cp437_BIN)
That's a good check but I'd have to introduce someone to a serious volley of high speed pork chops for making a true/false answer case sensitive. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
June 29, 2009 at 6:44 am
Maybe T means "Absolutely 100% true", and t means "well, maybe about 75% true, give or take..." ?
🙂
N 56°04'39.16"
E 12°55'05.25"
June 29, 2009 at 11:43 pm
thaks all for helping me...
June 30, 2009 at 10:37 am
Best is to leave the formatting and case conversions at the front end application, should try not to use SQL Server for formatting and case conversion tasks which are easily handled at the application side.
Rememer RDBMS are designed for data storage and data retrieval as quick as possible.
Thanks,
Amol
Amol Naik
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply