Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use variables when running an SQL query?

I am trying to put together the following query:

new_fid_num =  select max(fid)+1 from field;

insert into field values(new_fid_num, 'StartDate', 8, 'The first date that data is available on BMLL', 'T', 'T');

I am not quite sure how to translate it into SQL, I tried something using DECLARE but that doesn’t work. Any ideas how I can achieve the above?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you should be able to use your select statement AS the value such as

insert into field
( explicitColumnName1,
  explicitColumnName2,
  explicitColumnName3,
  explicitColumnName4,
  explicitColumnName5,
  explicitColumnName6 
)
values
( 
  ( select max(fid)+1 from field ),
  'StartDate', 
  8, 
  'The first date that data is available on BMLL', 
  'T', 
  'T'
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading