Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
please help in this query.

create table tbl_residential
(
id varchar(max) primary key not null 'R00'+identity(1,1),
categoryid varchar(10),
title varchar(max),
images varchar(max),
pdiscription varchar(max),
contact_no bigint,
city varchar(30),
location varchar(30),
property_type varchar(50),
rate_persquarefit float,
Layout_Plan varchar(max),
Floor_Plan varchar(max),
Unit_Plan varchar(max),

)
Posted
Comments
ZurdoDev 19-Mar-13 14:02pm    
What's the problem?
prakash00060 19-Mar-13 14:08pm    
i want to create id in a table as P0001.

how it is crated please help my sample code is shown above
ZurdoDev 19-Mar-13 14:21pm    
You need to do as Solution 1 says or not make it an identity field and you maintain the mask.

I'd do this instead:
create table [cpqaAnswers].[cpqa].[tblPZResidential]
(
	--id varchar(max) primary key not null 'R00' + identity(1,1),
	id [int]identity(1,1) primary key NOT NULL,
	idx varchar(max),
	categoryid varchar(10),
	title varchar(max),
	images varchar(max),
	pdiscription varchar(max),
	contact_no bigint,
	city varchar(30),
	location varchar(30),
	property_type varchar(50),
	rate_persquarefit float,
	Layout_Plan varchar(max),
	Floor_Plan varchar(max),
	Unit_Plan varchar(max),
 
)		

Then when it comes time to populate the table with data you perform a VALUES or INSERT of that 'R00' prefixing as "'R00' + CAST([id] As varchar)" in the appropriate place in the SELECT
 
Share this answer
 
v2
Comments
Maciej Los 19-Mar-13 14:24pm    
Absolutly right, +5!
See my previous post: Generate the id Like 'Cust001'[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900