Hi all,
I'm working on a SQL procedure to insert a row for new clients based on a template account that already exists in the database.
I thought about Declaring a variable and selecting the value from the table one at a time, but with many columns needed, this seems inefficient.
Sample Query:
DECLARE @Template_Account decimal(10,0) = 8;
DECLARE @Field1 ntext = (SELECT Field1 FROM cltClients WITH(NOLOCK) WHERE ClientNumber=@Template_Account)
DECLARE @Field2 ntext = (SELECT Field2 FROM cltClients WITH(NOLOCK) WHERE ClientNumber=@Template_Account)
DECLARE @Save1 bit = (SELECT Save1 FROM cltClients WITH(NOLOCK) WHERE ClientNumber=@Template_Account)
DECLARE @Checkin1 bit = (SELECT Checkin1 FROM cltClients WITH(NOLOCK) WHERE ClientNumber=@Template_Account)
DECLARE @Sandbox1 ntext = (SELECT Sandbox1 FROM cltClients WITH(NOLOCK) WHERE ClientNumber=@Template_Account)
INSERT INTO cltClients (Field1, Field2, Save1, Checkin1, Sandbox1)
VALUES(@Field1,@Field2,@Save1,@Checkin1,@Sandbox1);
I'm looking for a way to basically have one SELECT instead of 5 in the example above. Anyone know if that's possible in SQL Server?